package com.zcloud.fire.check.gatewayimpl;

import com.jjb.saas.framework.auth.utils.AuthContext;
import com.zcloud.fire.check.domain.gateway.FireCheckRecordPointGateway;
import com.zcloud.fire.check.domain.model.FireCheckRecordPointE;
import com.zcloud.fire.check.persistence.dataobject.FireCheckRecordPointDO;
import com.zcloud.fire.check.persistence.repository.FireCheckRecordPointRepository;
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:20
 */
@Service
@AllArgsConstructor
public class FireCheckRecordPointGatewayImpl implements FireCheckRecordPointGateway {
    private final FireCheckRecordPointRepository fireCheckRecordPointRepository;

    @Override
    public Boolean add(FireCheckRecordPointE fireCheckRecordPointE) {
        if(StringUtils.isEmpty(fireCheckRecordPointE.getFireRecordPointId())){
            fireCheckRecordPointE.setFireRecordPointId(Tools.get32UUID());
        }
        if(fireCheckRecordPointE.getCorpinfoId() == null){
            fireCheckRecordPointE.setCorpinfoId(AuthContext.getTenantId());
        }
        FireCheckRecordPointDO d = new FireCheckRecordPointDO();
        BeanUtils.copyProperties(fireCheckRecordPointE, d);
        fireCheckRecordPointRepository.save(d);
        fireCheckRecordPointE.setId(d.getId());
        return true;
    }

    @Override
    public Boolean update(FireCheckRecordPointE fireCheckRecordPointE) {
        FireCheckRecordPointDO d = new FireCheckRecordPointDO();
        BeanUtils.copyProperties(fireCheckRecordPointE, d);
        fireCheckRecordPointRepository.updateById(d);
        return true;
    }

    @Override
    public Boolean deletedFireCheckRecordPointById(Long id) {
        return fireCheckRecordPointRepository.removeById(id);
    }

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

