package com.zcloud.fire.check.gatewayimpl;

import com.jjb.saas.framework.auth.utils.AuthContext;
import com.zcloud.fire.check.domain.gateway.FirePointGateway;
import com.zcloud.fire.check.domain.model.FirePointE;
import com.zcloud.fire.check.persistence.dataobject.FirePointDO;
import com.zcloud.fire.check.persistence.repository.FirePointRepository;
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:12:54
 */
@Service
@AllArgsConstructor
public class FirePointGatewayImpl implements FirePointGateway {
    private final FirePointRepository firePointRepository;

    @Override
    public Boolean add(FirePointE firePointE) {
        if(StringUtils.isEmpty(firePointE.getFirePointId())){
            firePointE.setFirePointId(Tools.get32UUID());
        }
        if(firePointE.getCorpinfoId() == null){
            firePointE.setCorpinfoId(AuthContext.getTenantId());
        }
        FirePointDO d = new FirePointDO();
        BeanUtils.copyProperties(firePointE, d);
        firePointRepository.save(d);
        return true;
    }

    @Override
    public Boolean update(FirePointE firePointE) {
        FirePointDO d = new FirePointDO();
        BeanUtils.copyProperties(firePointE, d);
        firePointRepository.updateById(d);
        return true;
    }

    @Override
    public Boolean deletedFirePointById(Long id) {
        return firePointRepository.removeById(id);
    }

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

