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

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.ElementCollection;
import jakarta.persistence.EmbeddedId;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.FetchType;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;

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

import com.iqser.red.service.persistence.management.v1.processor.entity.dossier.FileEntity;
import com.iqser.red.service.persistence.service.v1.api.shared.model.annotations.AnnotationStatus;
import com.iqser.red.service.persistence.service.v1.api.shared.model.dossiertemplate.type.DictionaryEntryType;

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

@Data
@Entity
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Table(name = "manual_redaction")
public class ManualRedactionEntryEntity implements IBaseAnnotation {

    @EmbeddedId
    private AnnotationEntityId id;
    @Column(name = "user_id")
    private String user;
    @Column(length = 4000)
    private String typeId;
    @Column(length = 4000)
    private String value;
    @Column(length = 4000)
    private String reason;
    @Column
    private String legalBasis;
    @Column
    @Enumerated(EnumType.STRING)
    private AnnotationStatus status;
    @Column
    private String section;
    @Column
    private boolean rectangle;
    @Column
    private boolean addToDictionary;
    @Column
    private boolean addToAllDossiers;

    @Column
    @Deprecated
    private boolean addToDossierDictionary;

    @Column
    @Enumerated(EnumType.STRING)
    private DictionaryEntryType dictionaryEntryType;
    @Column
    private OffsetDateTime requestDate;
    @Column
    private OffsetDateTime processedDate;
    @Column
    private OffsetDateTime softDeletedTime;

    @ElementCollection
    @Fetch(FetchMode.SUBSELECT)
    private List<RectangleEntity> positions = new ArrayList<>();

    @ManyToOne(fetch = FetchType.LAZY)
    private FileEntity fileStatus;

    @Column
    private String textBefore;
    @Column
    private String textAfter;

    @Column
    private String sourceId;

    @ElementCollection
    @Fetch(value = FetchMode.SUBSELECT)
    private Set<String> typeIdsOfModifiedDictionaries = new HashSet<>();

}
