package com.zcloud.fire.check.gatewayimpl;

import com.jjb.saas.framework.auth.utils.AuthContext;
import com.zcloud.fire.check.domain.gateway.FireRegionGateway;
import com.zcloud.fire.check.domain.model.FireRegionE;
import com.zcloud.fire.check.persistence.dataobject.FireRegionDO;
import com.zcloud.fire.check.persistence.repository.FireRegionRepository;
import com.zcloud.gbscommon.utils.Tools;
import lombok.AllArgsConstructor;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * web-infrastructure
 *
 * @Author zhaokai
 * @Date 2025-11-26 10:13:09
 */
@Service
@AllArgsConstructor
public class FireRegionGatewayImpl implements FireRegionGateway {
    private final FireRegionRepository fireRegionRepository;

    @Override
    public Boolean add(FireRegionE fireRegionE) {
        if(StringUtils.isEmpty(fireRegionE.getFireRegionId())){
            fireRegionE.setFireRegionId(Tools.get32UUID());
        }
        if(fireRegionE.getCorpinfoId() == null){
            fireRegionE.setCorpinfoId(AuthContext.getTenantId());
        }
        FireRegionDO d = new FireRegionDO();
        BeanUtils.copyProperties(fireRegionE, d);
        fireRegionRepository.save(d);
        return true;
    }

    @Override
    public Boolean update(FireRegionE fireRegionE) {
        FireRegionDO d = new FireRegionDO();
        BeanUtils.copyProperties(fireRegionE, d);
        fireRegionRepository.updateById(d);
        return true;
    }

    @Override
    public Boolean deletedFireRegionById(Long id) {
        return fireRegionRepository.removeById(id);
    }

    @Override
    public Boolean deletedFireRegionByIds(Long[] ids) {
        List<Long> idList = Arrays.stream(ids).collect(Collectors.toList());
        return fireRegionRepository.removeByIds(idList);
    }
}

