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.QualFilingMaterialChangeAbility;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

/**
 * 删除备案申请材料-变更询执行器
 *
 * @author ltq
 * @date 2026-07-02 10:04:07
 */
@Component
@AllArgsConstructor
public class QualFilingMaterialChangeDelCmdExe {
    private final QualFilingMaterialChangeAbility qualFilingMaterialChangeAbility;

    /**
     * 根据IDS删除备案申请材料-变更对象
     *
     * @param ids 备案申请材料-变更ID数组
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public boolean execute(Long[] ids) {
        if (ObjectUtil.isEmpty(ids)) {
            throw new BizException("请传入正确的ID");
        }
        boolean deleteRes = qualFilingMaterialChangeAbility.deletedQualFilingMaterialChangeByIds(ids);
        if (!deleteRes) {
            throw new BizException("删除失败");
        }
        return true;
    }

    /**
     * 根据ID删除备案申请材料-变更对象
     *
     * @param id 删除备案申请材料-变更对象ID
     * @return
     */
    @Transactional(rollbackFor = Exception.class)
    public boolean execute(Long id) {
        boolean deleteRes = qualFilingMaterialChangeAbility.deletedQualFilingMaterialChangeById(id);
        if (!deleteRes) {
            throw new BizException("删除失败");
        }
        return true;
    }


}
