package org.qinan.safetyeval.infrastructure.gateway;

import lombok.AllArgsConstructor;
import org.qinan.safetyeval.domain.change.gateway.QualFilingPersonnelChangeGateway;
import org.qinan.safetyeval.domain.change.model.QualFilingPersonnelChangeE;
import org.qinan.safetyeval.infrastructure.convertor.QualFilingPersonnelChangeDoConvertor;
import org.qinan.safetyeval.infrastructure.persistence.domainobject.QualFilingPersonnelChangeDO;
import org.qinan.safetyeval.infrastructure.persistence.repository.QualFilingPersonnelChangeRepository;
import org.springframework.stereotype.Service;

/**
 * 备案申请人员-变更网关实现
 *
 * @Author: ltq
 * @date 2026-07-02 10:04:33
 */
@Service
@AllArgsConstructor
public class QualFilingPersonnelChangeGatewayImpl implements QualFilingPersonnelChangeGateway {
    private final QualFilingPersonnelChangeRepository qualFilingPersonnelChangeRepository;
    private final QualFilingPersonnelChangeDoConvertor qualFilingPersonnelChangeDoConvertor;

    @Override
    public Boolean add(QualFilingPersonnelChangeE qualFilingPersonnelChangeE) {
        QualFilingPersonnelChangeDO qualFilingPersonnelChangeDO = qualFilingPersonnelChangeDoConvertor.convertEeToDo(qualFilingPersonnelChangeE);
        boolean res = qualFilingPersonnelChangeRepository.addQualFilingPersonnelChange(qualFilingPersonnelChangeDO);
        if (res) {
            qualFilingPersonnelChangeE.setId(qualFilingPersonnelChangeDO.getId());
        }
        return res;
    }

    @Override
    public Boolean update(QualFilingPersonnelChangeE qualFilingPersonnelChangeE) {
        boolean res = qualFilingPersonnelChangeRepository.updateQualFilingPersonnelChange(qualFilingPersonnelChangeDoConvertor.convertEeToDo(qualFilingPersonnelChangeE));
        return res;
    }

    @Override
    public Boolean deletedQualFilingPersonnelChangeById(Long id) {
        return qualFilingPersonnelChangeRepository.deletedQualFilingPersonnelChangeById(id);
    }

    @Override
    public Boolean deletedQualFilingPersonnelChangeByIds(Long[] ids) {
        return qualFilingPersonnelChangeRepository.deletedQualFilingPersonnelChangeByIds(ids);
    }

    @Override
    public java.util.List<QualFilingPersonnelChangeE> listByFilingId(Long filingId) {
        return qualFilingPersonnelChangeDoConvertor.converDosToEes(
                qualFilingPersonnelChangeRepository.listByFilingId(filingId));
    }

    @Override
    public int countByFilingId(Long filingId) {
        return qualFilingPersonnelChangeRepository.countByFilingId(filingId);
    }

    @Override
    public int countByFilingIdAndRegisterEngineerFlag(Long filingId, Integer registerEngineerFlag) {
        return qualFilingPersonnelChangeRepository.countByFilingIdAndRegisterEngineerFlag(filingId, registerEngineerFlag);
    }

    @Override
    public int countByFilingIdAndJoinWorkDateAfter(Long filingId, java.time.LocalDate joinWorkDate) {
        return qualFilingPersonnelChangeRepository.countByFilingIdAndJoinWorkDateAfter(filingId, joinWorkDate);
    }
}
