package org.qinan.safetyeval.infrastructure.gateway;

import lombok.AllArgsConstructor;
import org.qinan.safetyeval.domain.change.gateway.QualFilingCommitmentChangeGateway;
import org.qinan.safetyeval.domain.change.model.QualFilingCommitmentChangeE;
import org.qinan.safetyeval.infrastructure.convertor.QualFilingCommitmentChangeDoConvertor;
import org.qinan.safetyeval.infrastructure.persistence.domainobject.QualFilingCommitmentChangeDO;
import org.qinan.safetyeval.infrastructure.persistence.repository.QualFilingCommitmentChangeRepository;
import org.springframework.stereotype.Service;

/**
 * 法定代人承诺书-变更网关实现
 *
 * @Author: ltq
 * @date 2026-07-02 09:38:30
 */
@Service
@AllArgsConstructor
public class QualFilingCommitmentChangeGatewayImpl implements QualFilingCommitmentChangeGateway {
    private final QualFilingCommitmentChangeRepository qualFilingCommitmentChangeRepository;
    private final QualFilingCommitmentChangeDoConvertor qualFilingCommitmentChangeDoConvertor;

    @Override
    public Boolean add(QualFilingCommitmentChangeE qualFilingCommitmentChangeE) {
        QualFilingCommitmentChangeDO qualFilingCommitmentChangeDO = qualFilingCommitmentChangeDoConvertor.convertEeToDo(qualFilingCommitmentChangeE);
        boolean res = qualFilingCommitmentChangeRepository.addQualFilingCommitmentChange(qualFilingCommitmentChangeDO);
        if (res) {
            qualFilingCommitmentChangeE.setId(qualFilingCommitmentChangeDO.getId());
        }
        return res;
    }

    @Override
    public Boolean update(QualFilingCommitmentChangeE qualFilingCommitmentChangeE) {
        boolean res = qualFilingCommitmentChangeRepository.updateQualFilingCommitmentChange(qualFilingCommitmentChangeDoConvertor.convertEeToDo(qualFilingCommitmentChangeE));
        return res;
    }

    @Override
    public Boolean deletedQualFilingCommitmentChangeById(Long id) {
        return qualFilingCommitmentChangeRepository.deletedQualFilingCommitmentChangeById(id);
    }

    @Override
    public Boolean deletedQualFilingCommitmentChangeByIds(Long[] ids) {
        return qualFilingCommitmentChangeRepository.deletedQualFilingCommitmentChangeByIds(ids);
    }

    @Override
    public QualFilingCommitmentChangeE getByFilingId(Long filingId) {
        QualFilingCommitmentChangeDO dataObject = qualFilingCommitmentChangeRepository.getByFilingId(filingId);
        if (dataObject == null) {
            return null;
        }
        return qualFilingCommitmentChangeDoConvertor.converDoToEe(dataObject);
    }
}
