package com.zcloud.fire.check.gatewayimpl;

import com.jjb.saas.framework.auth.utils.AuthContext;
import com.zcloud.fire.check.domain.gateway.FireDeviceGateway;
import com.zcloud.fire.check.domain.model.FireDeviceE;
import com.zcloud.fire.check.persistence.dataobject.FireDeviceDO;
import com.zcloud.fire.check.persistence.repository.FireDeviceRepository;
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:34
 */
@Service
@AllArgsConstructor
public class FireDeviceGatewayImpl implements FireDeviceGateway {
    private final FireDeviceRepository fireDeviceRepository;

    @Override
    public Boolean add(FireDeviceE fireDeviceE) {
        if(StringUtils.isEmpty(fireDeviceE.getFireDeviceId())){
            fireDeviceE.setFireDeviceId(Tools.get32UUID());
        }
        if(fireDeviceE.getCorpinfoId() == null){
            fireDeviceE.setCorpinfoId(AuthContext.getTenantId());
        }
        FireDeviceDO d = new FireDeviceDO();
        BeanUtils.copyProperties(fireDeviceE, d);
        fireDeviceRepository.save(d);
        return true;
    }

    @Override
    public Boolean update(FireDeviceE fireDeviceE) {
        FireDeviceDO d = new FireDeviceDO();
        BeanUtils.copyProperties(fireDeviceE, d);
        fireDeviceRepository.updateById(d);
        return true;
    }

    @Override
    public Boolean deletedFireDeviceById(Long id) {
        return fireDeviceRepository.removeById(id);
    }

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

