package org.qinan.safetyeval.infrastructure.persistence.repository.impl;

import cn.hutool.core.util.ObjectUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.jjb.saas.framework.enums.enums.BooleanEnum;
import com.jjb.saas.framework.repository.repo.impl.BaseRepositoryImpl;
import lombok.AllArgsConstructor;
import org.qinan.safetyeval.client.change.request.QualFilingCommitmentChangePageQry;
import org.qinan.safetyeval.domain.constant.BooleanQAEnum;
import org.qinan.safetyeval.infrastructure.persistence.domainobject.QualFilingCommitmentChangeDO;
import org.qinan.safetyeval.infrastructure.persistence.mapper.QualFilingCommitmentChangeMapper;
import org.qinan.safetyeval.infrastructure.persistence.repository.QualFilingCommitmentChangeRepository;
import org.springframework.stereotype.Service;

import java.util.Arrays;

/**
 * 法定代人承诺书-变更
 *
 * @Author: ltq
 * @date 2026-07-02 09:38:30
 */
@Service
@AllArgsConstructor
public class QualFilingCommitmentChangeRepositoryImpl extends BaseRepositoryImpl<QualFilingCommitmentChangeMapper, QualFilingCommitmentChangeDO> implements QualFilingCommitmentChangeRepository {

    private final QualFilingCommitmentChangeMapper qualFilingCommitmentChangeMapper;

    @Override
    public QualFilingCommitmentChangeDO getById(Long id) {
        return super.lambdaQuery().eq(QualFilingCommitmentChangeDO::getId, id).eq(QualFilingCommitmentChangeDO::getDeleteEnum, BooleanQAEnum.FALSE.getValue()).one();
    }

    @Override
    public IPage<QualFilingCommitmentChangeDO> listQualFilingCommitmentChangePage(IPage iPage, QualFilingCommitmentChangePageQry qualFilingCommitmentChangePageQry) {
        QueryWrapper<QualFilingCommitmentChangeDO> qualFilingCommitmentChangeDoQueryWrapper = new QueryWrapper<>();
        if (ObjectUtil.isNotEmpty(qualFilingCommitmentChangePageQry.getFilingChangeId())) {
            qualFilingCommitmentChangeDoQueryWrapper.eq("filing_change_id", qualFilingCommitmentChangePageQry.getFilingChangeId());
        }
        if (ObjectUtil.isNotEmpty(qualFilingCommitmentChangePageQry.getCommitmentContent())) {
            qualFilingCommitmentChangeDoQueryWrapper.eq("commitment_content", qualFilingCommitmentChangePageQry.getCommitmentContent());
        }
        if (ObjectUtil.isNotEmpty(qualFilingCommitmentChangePageQry.getLegalRepSignatureUrl())) {
            qualFilingCommitmentChangeDoQueryWrapper.eq("legal_rep_signature_url", qualFilingCommitmentChangePageQry.getLegalRepSignatureUrl());
        }
        if (ObjectUtil.isNotEmpty(qualFilingCommitmentChangePageQry.getSignDate())) {
            qualFilingCommitmentChangeDoQueryWrapper.eq("sign_date", qualFilingCommitmentChangePageQry.getSignDate());
        }
        if (ObjectUtil.isNotEmpty(qualFilingCommitmentChangePageQry.getLegalRepPersonnelId())) {
            qualFilingCommitmentChangeDoQueryWrapper.eq("legal_rep_personnel_id", qualFilingCommitmentChangePageQry.getLegalRepPersonnelId());
        }
        if (ObjectUtil.isNotEmpty(qualFilingCommitmentChangePageQry.getLegalRepName())) {
            qualFilingCommitmentChangeDoQueryWrapper.like("legal_rep_name", qualFilingCommitmentChangePageQry.getLegalRepName());
        }
        if (ObjectUtil.isNotEmpty(qualFilingCommitmentChangePageQry.getEnv())) {
            qualFilingCommitmentChangeDoQueryWrapper.eq("env", qualFilingCommitmentChangePageQry.getEnv());
        }
        qualFilingCommitmentChangeDoQueryWrapper.eq("delete_enum", BooleanQAEnum.FALSE.getValue());
        return qualFilingCommitmentChangeMapper.selectPage(iPage, qualFilingCommitmentChangeDoQueryWrapper);
    }

    @Override
    public Boolean addQualFilingCommitmentChange(QualFilingCommitmentChangeDO qualFilingCommitmentChangeDO) {
        return super.save(qualFilingCommitmentChangeDO);
    }

    @Override
    public Boolean updateQualFilingCommitmentChange(QualFilingCommitmentChangeDO qualFilingCommitmentChangeDO) {
        return super.updateById(qualFilingCommitmentChangeDO);
    }

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

    @Override
    public Boolean deletedQualFilingCommitmentChangeByIds(Long[] ids) {
        return super.removeBatchEnByIds(Arrays.asList(ids));
    }

    @Override
    public QualFilingCommitmentChangeDO getByFilingId(Long filingId) {
        return super.lambdaQuery()
                .eq(QualFilingCommitmentChangeDO::getFilingChangeId, filingId)
                .eq(QualFilingCommitmentChangeDO::getDeleteEnum, BooleanQAEnum.FALSE.getValue())
                .one();
    }
}
