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

import com.alibaba.cola.exception.BizException;
import lombok.AllArgsConstructor;
import org.qinan.safetyeval.app.change.convertor.QualFilingMaterialChangeCmdConvertor;
import org.qinan.safetyeval.client.change.request.QualFilingMaterialChangeAddCmd;
import org.qinan.safetyeval.domain.change.ability.QualFilingMaterialChangeAbility;
import org.qinan.safetyeval.domain.change.model.QualFilingMaterialChangeE;
import org.qinan.safetyeval.infrastructure.persistence.queryservice.QualFilingMaterialChangeQueryService;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

/**
 * 新增备案申请材料-变更执行器
 *
 * @author ltq
 * @date 2026-07-02 10:04:07
 */
@Component
@AllArgsConstructor
public class QualFilingMaterialChangeAddCmdExe {

    private final QualFilingMaterialChangeQueryService qualFilingMaterialChangeQueryService;
    private final QualFilingMaterialChangeCmdConvertor qualFilingMaterialChangeCmdConvertor;
    private final QualFilingMaterialChangeAbility qualFilingMaterialChangeAbility;

    /**
     * 新增备案申请材料-变更
     *
     * @param qualFilingMaterialChangeAddCmd 新增备案申请材料-变更对象
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public boolean execute(QualFilingMaterialChangeAddCmd qualFilingMaterialChangeAddCmd) {
        QualFilingMaterialChangeE qualFilingMaterialChangeE = qualFilingMaterialChangeCmdConvertor.convertCmdToE(qualFilingMaterialChangeAddCmd);
        boolean res = qualFilingMaterialChangeE.add();
        if (!res) {
            throw new BizException("保存失败");
        }
        return true;
    }
}
