package org.qinan.safetyeval.app.change.executor.command;

import com.alibaba.cola.exception.BizException;
import lombok.AllArgsConstructor;
import org.qinan.safetyeval.app.change.convertor.QualFilingCommitmentChangeCmdConvertor;
import org.qinan.safetyeval.client.change.request.QualFilingCommitmentChangeAddCmd;
import org.qinan.safetyeval.domain.change.ability.QualFilingCommitmentChangeAbility;
import org.qinan.safetyeval.domain.change.model.QualFilingCommitmentChangeE;
import org.qinan.safetyeval.infrastructure.persistence.queryservice.QualFilingCommitmentChangeQueryService;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

/**
 * 新增法定代人承诺书-变更执行器
 *
 * @author ltq
 * @date 2026-07-02 09:38:30
 */
@Component
@AllArgsConstructor
public class QualFilingCommitmentChangeAddCmdExe {

    private final QualFilingCommitmentChangeQueryService qualFilingCommitmentChangeQueryService;
    private final QualFilingCommitmentChangeCmdConvertor qualFilingCommitmentChangeCmdConvertor;
    private final QualFilingCommitmentChangeAbility qualFilingCommitmentChangeAbility;

    /**
     * 新增法定代人承诺书-变更
     *
     * @param qualFilingCommitmentChangeAddCmd 新增法定代人承诺书-变更对象
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public boolean execute(QualFilingCommitmentChangeAddCmd qualFilingCommitmentChangeAddCmd) {
        QualFilingCommitmentChangeE qualFilingCommitmentChangeE = qualFilingCommitmentChangeCmdConvertor.convertCmdToE(qualFilingCommitmentChangeAddCmd);
        boolean res = qualFilingCommitmentChangeE.add();
        if (!res) {
            throw new BizException("保存失败");
        }
        return true;
    }
}
