package dev.lions.unionflow.server.mapper.mutuelle.credit;

import dev.lions.unionflow.server.api.dto.mutuelle.credit.DemandeCreditRequest;
import dev.lions.unionflow.server.api.dto.mutuelle.credit.DemandeCreditResponse;
import dev.lions.unionflow.server.entity.mutuelle.credit.DemandeCredit;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;

@Mapper(componentModel = "jakarta-cdi", uses = {
        EcheanceCreditMapper.class }, builder = @org.mapstruct.Builder(disableBuilder = true))
public interface DemandeCreditMapper {

    @Mapping(target = "membreId", source = "membre.id")
    @Mapping(target = "compteLieId", source = "compteLie.id")
    DemandeCreditResponse toDto(DemandeCredit entity);

    @Mapping(target = "id", ignore = true)
    @Mapping(target = "dateCreation", ignore = true)
    @Mapping(target = "dateModification", ignore = true)
    @Mapping(target = "creePar", ignore = true)
    @Mapping(target = "modifiePar", ignore = true)
    @Mapping(target = "version", ignore = true)
    @Mapping(target = "actif", ignore = true)
    @Mapping(target = "membre", ignore = true)
    @Mapping(target = "compteLie", ignore = true)
    @Mapping(target = "echeancier", ignore = true)
    @Mapping(target = "garanties", ignore = true)
    @Mapping(target = "numeroDossier", ignore = true)
    @Mapping(target = "statut", ignore = true)
    @Mapping(target = "dateSoumission", ignore = true)
    @Mapping(target = "dateValidation", ignore = true)
    @Mapping(target = "notesComite", ignore = true)
    @Mapping(target = "dureeMoisDemande", source = "dureeMois")
    @Mapping(target = "montantApprouve", ignore = true)
    @Mapping(target = "dureeMoisApprouvee", ignore = true)
    @Mapping(target = "tauxInteretAnnuel", ignore = true)
    @Mapping(target = "coutTotalCredit", ignore = true)
    @Mapping(target = "datePremierEcheance", ignore = true)
    DemandeCredit toEntity(DemandeCreditRequest request);

    @Mapping(target = "id", ignore = true)
    @Mapping(target = "dateCreation", ignore = true)
    @Mapping(target = "dateModification", ignore = true)
    @Mapping(target = "creePar", ignore = true)
    @Mapping(target = "modifiePar", ignore = true)
    @Mapping(target = "version", ignore = true)
    @Mapping(target = "actif", ignore = true)
    @Mapping(target = "membre", ignore = true)
    @Mapping(target = "compteLie", ignore = true)
    @Mapping(target = "echeancier", ignore = true)
    @Mapping(target = "garanties", ignore = true)
    @Mapping(target = "numeroDossier", ignore = true)
    @Mapping(target = "statut", ignore = true)
    @Mapping(target = "dateSoumission", ignore = true)
    @Mapping(target = "dateValidation", ignore = true)
    @Mapping(target = "notesComite", ignore = true)
    @Mapping(target = "dureeMoisDemande", ignore = true)
    @Mapping(target = "montantApprouve", ignore = true)
    @Mapping(target = "dureeMoisApprouvee", ignore = true)
    @Mapping(target = "tauxInteretAnnuel", ignore = true)
    @Mapping(target = "coutTotalCredit", ignore = true)
    @Mapping(target = "datePremierEcheance", ignore = true)
    void updateEntityFromDto(DemandeCreditRequest request, @MappingTarget DemandeCredit entity);
}
