package org.qinan.safetyeval.infrastructure.gateway;

import lombok.AllArgsConstructor;
import org.qinan.safetyeval.domain.change.gateway.QualFilingMaterialChangeGateway;
import org.qinan.safetyeval.domain.change.model.QualFilingMaterialChangeE;
import org.qinan.safetyeval.infrastructure.convertor.QualFilingMaterialChangeDoConvertor;
import org.qinan.safetyeval.infrastructure.persistence.domainobject.QualFilingMaterialChangeDO;
import org.qinan.safetyeval.infrastructure.persistence.repository.QualFilingMaterialChangeRepository;
import org.springframework.stereotype.Service;

/**
 * 备案申请材料-变更网关实现
 *
 * @Author: ltq
 * @date 2026-07-02 10:04:07
 */
@Service
@AllArgsConstructor
public class QualFilingMaterialChangeGatewayImpl implements QualFilingMaterialChangeGateway {
    private final QualFilingMaterialChangeRepository qualFilingMaterialChangeRepository;
    private final QualFilingMaterialChangeDoConvertor qualFilingMaterialChangeDoConvertor;

    @Override
    public Boolean add(QualFilingMaterialChangeE qualFilingMaterialChangeE) {
        QualFilingMaterialChangeDO qualFilingMaterialChangeDO = qualFilingMaterialChangeDoConvertor.convertEeToDo(qualFilingMaterialChangeE);
        boolean res = qualFilingMaterialChangeRepository.addQualFilingMaterialChange(qualFilingMaterialChangeDO);
        if (res) {
            qualFilingMaterialChangeE.setId(qualFilingMaterialChangeDO.getId());
        }
        return res;
    }

    @Override
    public Boolean update(QualFilingMaterialChangeE qualFilingMaterialChangeE) {
        boolean res = qualFilingMaterialChangeRepository.updateQualFilingMaterialChange(qualFilingMaterialChangeDoConvertor.convertEeToDo(qualFilingMaterialChangeE));
        return res;
    }

    @Override
    public Boolean deletedQualFilingMaterialChangeById(Long id) {
        return qualFilingMaterialChangeRepository.deletedQualFilingMaterialChangeById(id);
    }

    @Override
    public Boolean deletedQualFilingMaterialChangeByIds(Long[] ids) {
        return qualFilingMaterialChangeRepository.deletedQualFilingMaterialChangeByIds(ids);
    }

    @Override
    public java.util.List<QualFilingMaterialChangeE> listByFilingId(Long filingId) {
        return qualFilingMaterialChangeDoConvertor.converDosToEes(
                qualFilingMaterialChangeRepository.listByFilingId(filingId));
    }

    @Override
    public int countByFilingIdAndUploadStatusCodeAndMaterialType(Long filingId, Integer uploadStatusCode, String materialType) {
        return qualFilingMaterialChangeRepository.countByFilingIdAndUploadStatusCodeAndMaterialType(filingId, uploadStatusCode, materialType);
    }
}
