package com.iqser.red.service.persistence.management.v1.processor.entity.dossier;

import java.time.OffsetDateTime;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

import jakarta.persistence.Column;
import jakarta.persistence.Convert;
import jakarta.persistence.Entity;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import jakarta.persistence.Transient;

import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;

import com.iqser.red.service.persistence.management.v1.processor.entity.configuration.TypeEntity;
import com.iqser.red.service.persistence.management.v1.processor.entity.configuration.WatermarkEntity;
import com.iqser.red.service.persistence.management.v1.processor.utils.JSONDownloadFileTypeConverter;
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.DossierTemplateStatus;
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.DownloadFileType;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Entity
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Table(name = "dossier_template")
public class DossierTemplateEntity {

    @Id
    private String id;

    @Column(name = "name")
    private String name;

    @Column(length = 4000)
    private String description;

    @Column
    private OffsetDateTime dateAdded;

    @Column
    private OffsetDateTime dateModified;

    @Column
    private String createdBy;

    @Column
    private String modifiedBy;

    @Column
    private OffsetDateTime validFrom;

    @Column
    private OffsetDateTime validTo;

    @Column(name = "soft_delete_time")
    private OffsetDateTime softDeleteTime;

    @Column(name = "keep_image_metadata")
    private boolean keepImageMetadata;

    @Column(name = "keep_hidden_text")
    private boolean keepHiddenText;

    @Column(name = "keep_overlapping_objects")
    private boolean keepOverlappingObjects;

    @Column(name = "apply_dictionary_updates_to_all_dossiers_by_default")
    private boolean applyDictionaryUpdatesToAllDossiersByDefault;

    @Column(name = "ocr_by_default")
    private boolean ocrByDefault;

    @Column(name = "remove_watermark")
    private boolean removeWatermark;

    @Builder.Default
    @Column(columnDefinition = "text", name = "download_file_types")
    @Convert(converter = JSONDownloadFileTypeConverter.class)
    private Set<DownloadFileType> downloadFileTypes = new HashSet<>();

    @Builder.Default
    @OneToMany(mappedBy = "dossierTemplate")
    @Fetch(FetchMode.SUBSELECT)
    private List<ReportTemplateEntity> reportTemplates = new ArrayList<>();

    @Builder.Default
    @OneToMany(mappedBy = "dossierTemplate")
    @Fetch(FetchMode.SUBSELECT)
    private List<TypeEntity> dossierTypes = new ArrayList<>();

    @Builder.Default
    @OneToMany(mappedBy = "dossierTemplate")
    @Fetch(FetchMode.SUBSELECT)
    private List<DossierEntity> dossiers = new ArrayList<>();

    @Builder.Default
    @Fetch(FetchMode.SUBSELECT)
    @OneToMany(mappedBy = "dossierTemplate")
    private List<FileAttributeConfigEntity> fileAttributeConfigs = new ArrayList<>();

    @Builder.Default
    @Fetch(FetchMode.SUBSELECT)
    @OneToMany(mappedBy = "dossierTemplate")
    private List<DossierStatusEntity> dossierStatusList = new ArrayList<>();

    @Builder.Default
    @Fetch(FetchMode.SUBSELECT)
    @OneToMany(mappedBy = "dossierTemplate")
    private List<WatermarkEntity> watermarkConfigs = new ArrayList<>();

    @Transient
    private DossierTemplateStatus dossierTemplateStatus;



}
