package com.zcloud.zcGbsServicer.command;

import com.zcloud.zcGbsServicer.domain.enums.PersonTypeEnum;
import com.zcloud.zcGbsServicer.domain.gateway.RescueTeamGateway;
import com.alibaba.cola.exception.BizException;
import com.zcloud.zcGbsServicer.domain.gateway.ResourcePersonGateway;
import com.zcloud.zcGbsServicer.persistence.dataobject.RescueTeamDO;
import com.zcloud.zcGbsServicer.persistence.repository.RescueTeamRepository;
import lombok.AllArgsConstructor;
import lombok.val;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;




/**
* web-app
* @Author makejava
* @Date 2026-01-21 17:23:00
*/
@Component
@AllArgsConstructor
public class RescueTeamRemoveExe {
    private final RescueTeamGateway rescueTeamGateway;
    private final RescueTeamRepository rescueTeamRepository;
    private final ResourcePersonGateway resourcePersonGateway;

    @Transactional(rollbackFor = Exception.class)
    public boolean execute(Long id) {
        RescueTeamDO rescueTeamDO = rescueTeamRepository.getById(id);
        Boolean resDelPer = resourcePersonGateway.deletedResourcePersonByBizId(rescueTeamDO.getTeamId(), PersonTypeEnum.RESCUE_TEAM.getCode());
        boolean res = rescueTeamGateway.deletedRescueTeamById(id);
        if(!res || !resDelPer){
            throw new BizException("删除失败");
        }
        return true;
    }

    @Transactional(rollbackFor = Exception.class)
    public boolean execute(Long[] ids) {
        boolean res = rescueTeamGateway.deletedRescueTeamByIds(ids);
        if(!res){
            throw new BizException("删除失败");
        }
        return true;
    }
}

