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

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.cola.exception.BizException;
import lombok.AllArgsConstructor;
import org.qinan.safetyeval.domain.change.ability.QualFilingCommitmentChangeAbility;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

/**
 * 删除法定代人承诺书-变更询执行器
 *
 * @author ltq
 * @date 2026-07-02 09:38:30
 */
@Component
@AllArgsConstructor
public class QualFilingCommitmentChangeDelCmdExe {
    private final QualFilingCommitmentChangeAbility qualFilingCommitmentChangeAbility;

    /**
     * 根据IDS删除法定代人承诺书-变更对象
     *
     * @param ids 法定代人承诺书-变更ID数组
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public boolean execute(Long[] ids) {
        if (ObjectUtil.isEmpty(ids)) {
            throw new BizException("请传入正确的ID");
        }
        boolean deleteRes = qualFilingCommitmentChangeAbility.deletedQualFilingCommitmentChangeByIds(ids);
        if (!deleteRes) {
            throw new BizException("删除失败");
        }
        return true;
    }

    /**
     * 根据ID删除法定代人承诺书-变更对象
     *
     * @param id 删除法定代人承诺书-变更对象ID
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public boolean execute(Long id) {
        boolean deleteRes = qualFilingCommitmentChangeAbility.deletedQualFilingCommitmentChangeById(id);
        if (!deleteRes) {
            throw new BizException("删除失败");
        }
        return true;
    }


}
