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

import dev.lions.unionflow.server.api.dto.mutuelle.epargne.TransactionEpargneRequest;
import dev.lions.unionflow.server.api.dto.mutuelle.epargne.TransactionEpargneResponse;
import dev.lions.unionflow.server.entity.mutuelle.epargne.TransactionEpargne;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;

@Mapper(componentModel = "cdi", builder = @org.mapstruct.Builder(disableBuilder = true))
public interface TransactionEpargneMapper {

    @Mapping(target = "compteId", source = "compte.id")
    @Mapping(target = "pieceJustificativeId", expression = "java(entity.getPieceJustificativeId() != null ? entity.getPieceJustificativeId().toString() : null)")
    TransactionEpargneResponse toDto(TransactionEpargne 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 = "compte", ignore = true)
    @Mapping(target = "type", source = "typeTransaction")
    @Mapping(target = "soldeAvant", ignore = true)
    @Mapping(target = "soldeApres", ignore = true)
    @Mapping(target = "dateTransaction", ignore = true)
    @Mapping(target = "operateurId", ignore = true)
    @Mapping(target = "referenceExterne", ignore = true)
    @Mapping(target = "statutExecution", ignore = true)
    @Mapping(target = "origineFonds", source = "origineFonds")
    @Mapping(target = "pieceJustificativeId", ignore = true)
    TransactionEpargne toEntity(TransactionEpargneRequest 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 = "compte", ignore = true)
    @Mapping(target = "type", source = "typeTransaction")
    @Mapping(target = "soldeAvant", ignore = true)
    @Mapping(target = "soldeApres", ignore = true)
    @Mapping(target = "dateTransaction", ignore = true)
    @Mapping(target = "operateurId", ignore = true)
    @Mapping(target = "referenceExterne", ignore = true)
    @Mapping(target = "statutExecution", ignore = true)
    @Mapping(target = "origineFonds", source = "origineFonds")
    @Mapping(target = "pieceJustificativeId", ignore = true)
    void updateEntityFromDto(TransactionEpargneRequest request, @MappingTarget TransactionEpargne entity);
}
