package com.iqser.red.service.persistence.management.v1.processor.mapper;

import org.mapstruct.AfterMapping;
import org.mapstruct.Context;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

import com.iqser.red.service.persistence.management.v1.processor.entity.annotations.AnnotationEntityId;
import com.iqser.red.service.persistence.management.v1.processor.entity.annotations.IdRemovalEntity;
import com.iqser.red.service.persistence.management.v1.processor.entity.annotations.ManualForceRedactionEntity;
import com.iqser.red.service.persistence.management.v1.processor.entity.annotations.ManualLegalBasisChangeEntity;
import com.iqser.red.service.persistence.management.v1.processor.entity.annotations.ManualRecategorizationEntity;
import com.iqser.red.service.persistence.management.v1.processor.entity.annotations.ManualRedactionEntryEntity;
import com.iqser.red.service.persistence.management.v1.processor.entity.annotations.ManualResizeRedactionEntity;
import com.iqser.red.service.persistence.management.v1.processor.entity.dossier.FileEntity;
import com.iqser.red.service.persistence.management.v1.processor.dataexchange.models.manualchanges.ManualAddExportModel;
import com.iqser.red.service.persistence.management.v1.processor.dataexchange.models.manualchanges.ManualForceExportModel;
import com.iqser.red.service.persistence.management.v1.processor.dataexchange.models.manualchanges.ManualLegalBasisChangeExportModel;
import com.iqser.red.service.persistence.management.v1.processor.dataexchange.models.manualchanges.ManualRecategorizationExportModel;
import com.iqser.red.service.persistence.management.v1.processor.dataexchange.models.manualchanges.ManualRemoveExportModel;
import com.iqser.red.service.persistence.management.v1.processor.dataexchange.models.manualchanges.ManualResizeExportModel;

@Mapper
public interface ManualChangesExportMapper {

    ManualChangesExportMapper INSTANCE = Mappers.getMapper(ManualChangesExportMapper.class);


    @Mappings({@Mapping(source = "id.annotationId", target = "annotationId")})
    ManualLegalBasisChangeExportModel toModel(ManualLegalBasisChangeEntity entity);


    @Mappings({@Mapping(source = "id.annotationId", target = "annotationId")})
    ManualForceExportModel toModel(ManualForceRedactionEntity entity);


    @Mappings({@Mapping(source = "id.annotationId", target = "annotationId")})
    ManualAddExportModel toModel(ManualRedactionEntryEntity entity);


    @Mappings({@Mapping(source = "id.annotationId", target = "annotationId")})
    ManualRemoveExportModel toModel(IdRemovalEntity entity);


    @Mappings({@Mapping(source = "id.annotationId", target = "annotationId")})
    ManualRecategorizationExportModel toModel(ManualRecategorizationEntity entity);


    @Mappings({@Mapping(source = "id.annotationId", target = "annotationId")})
    ManualResizeExportModel toModel(ManualResizeRedactionEntity entity);


    ManualLegalBasisChangeEntity toEntity(ManualLegalBasisChangeExportModel model, @Context FileEntity file, @Context String userId);


    ManualForceRedactionEntity toEntity(ManualForceExportModel model, @Context FileEntity file, @Context String userId);


    ManualRedactionEntryEntity toEntity(ManualAddExportModel model, @Context FileEntity file, @Context String userId);


    IdRemovalEntity toEntity(ManualRemoveExportModel model, @Context FileEntity file, @Context String userId);


    ManualRecategorizationEntity toEntity(ManualRecategorizationExportModel model, @Context FileEntity file, @Context String userId);


    ManualResizeRedactionEntity toEntity(ManualResizeExportModel model, @Context FileEntity file, @Context String userId);


    @AfterMapping
    default void setFileStatusAndId(ManualLegalBasisChangeExportModel model,
                                    @MappingTarget ManualLegalBasisChangeEntity entity,
                                    @Context FileEntity file,
                                    @Context String userId) {

        AnnotationEntityId annotationEntityId = new AnnotationEntityId(model.getAnnotationId(), file.getId());
        entity.setId(annotationEntityId);
        entity.setFileStatus(file);
        entity.setUser(userId);
    }


    @AfterMapping
    default void setFileStatusAndId(ManualRecategorizationExportModel model,
                                    @MappingTarget ManualRecategorizationEntity entity,
                                    @Context FileEntity file,
                                    @Context String userId) {

        AnnotationEntityId annotationEntityId = new AnnotationEntityId(model.getAnnotationId(), file.getId());
        entity.setId(annotationEntityId);
        entity.setFileStatus(file);
        entity.setUser(userId);
    }


    @AfterMapping
    default void setFileStatusAndId(ManualAddExportModel model,
                                    @MappingTarget ManualRedactionEntryEntity entity,
                                    @Context FileEntity file,
                                    @Context String userId) {

        AnnotationEntityId annotationEntityId = new AnnotationEntityId(model.getAnnotationId(), file.getId());
        entity.setId(annotationEntityId);
        entity.setFileStatus(file);
        entity.setUser(userId);
    }


    @AfterMapping
    default void setFileStatusAndId(ManualResizeExportModel model,
                                    @MappingTarget ManualResizeRedactionEntity entity,
                                    @Context FileEntity file,
                                    @Context String userId) {

        AnnotationEntityId annotationEntityId = new AnnotationEntityId(model.getAnnotationId(), file.getId());
        entity.setId(annotationEntityId);
        entity.setFileStatus(file);
        entity.setUser(userId);
    }


    @AfterMapping
    default void setFileStatusAndId(ManualForceExportModel model,
                                    @MappingTarget ManualForceRedactionEntity entity,
                                    @Context FileEntity file,
                                    @Context String userId) {

        AnnotationEntityId annotationEntityId = new AnnotationEntityId(model.getAnnotationId(), file.getId());
        entity.setId(annotationEntityId);
        entity.setFileStatus(file);
        entity.setUser(userId);
    }


    @AfterMapping
    default void setFileStatusAndId(ManualRemoveExportModel model, @MappingTarget IdRemovalEntity entity, @Context FileEntity file, @Context String userId) {

        AnnotationEntityId annotationEntityId = new AnnotationEntityId(model.getAnnotationId(), file.getId());
        entity.setId(annotationEntityId);
        entity.setFileStatus(file);
        entity.setUser(userId);
    }

}
