package com.zcloud.fire.check.gatewayimpl;

import com.jjb.saas.framework.auth.utils.AuthContext;
import com.zcloud.fire.check.domain.gateway.FireCheckRecordDeviceGateway;
import com.zcloud.fire.check.domain.model.FireCheckRecordDeviceE;
import com.zcloud.fire.check.persistence.dataobject.FireCheckRecordDeviceDO;
import com.zcloud.fire.check.persistence.repository.FireCheckRecordDeviceRepository;
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.Collections;

/**
 * web-infrastructure
 *
 * @Author zhaokai
 * @Date 2025-12-12 11:10:03
 */
@Service
@AllArgsConstructor
public class FireCheckRecordDeviceGatewayImpl implements FireCheckRecordDeviceGateway {
    private final FireCheckRecordDeviceRepository fireCheckRecordDeviceRepository;

    @Override
    public Boolean add(FireCheckRecordDeviceE fireCheckRecordDeviceE) {
        if(StringUtils.isEmpty(fireCheckRecordDeviceE.getFireRecordDeviceId())){
            fireCheckRecordDeviceE.setFireRecordDeviceId(Tools.get32UUID());
        }
        if(fireCheckRecordDeviceE.getCorpinfoId() == null){
            fireCheckRecordDeviceE.setCorpinfoId(AuthContext.getTenantId());
        }
        FireCheckRecordDeviceDO d = new FireCheckRecordDeviceDO();
        BeanUtils.copyProperties(fireCheckRecordDeviceE, d);
        fireCheckRecordDeviceRepository.save(d);
        return true;
    }

    @Override
    public Boolean update(FireCheckRecordDeviceE fireCheckRecordDeviceE) {
        FireCheckRecordDeviceDO d = new FireCheckRecordDeviceDO();
        BeanUtils.copyProperties(fireCheckRecordDeviceE, d);
        fireCheckRecordDeviceRepository.updateById(d);
        return true;
    }

    @Override
    public Boolean deletedFireCheckRecordDeviceById(Long id) {
        return fireCheckRecordDeviceRepository.removeById(id);
    }

    @Override
    public Boolean deletedFireCheckRecordDeviceByIds(Long[] ids) {
        return fireCheckRecordDeviceRepository.removeByIds(Collections.singletonList(ids));
    }


}

