package com.zcloud.fire.check.gatewayimpl;

import com.jjb.saas.framework.auth.utils.AuthContext;
import com.zcloud.fire.check.domain.gateway.FireCheckListGateway;
import com.zcloud.fire.check.domain.model.FireCheckListE;
import com.zcloud.fire.check.persistence.dataobject.FireCheckListDO;
import com.zcloud.fire.check.persistence.repository.FireCheckListRepository;
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-28 10:32:09
 */
@Service
@AllArgsConstructor
public class FireCheckListGatewayImpl implements FireCheckListGateway {
    private final FireCheckListRepository fireCheckListRepository;

    @Override
    public Boolean add(FireCheckListE fireCheckListE) {
        if(StringUtils.isEmpty(fireCheckListE.getFireCheckId())){
            fireCheckListE.setFireCheckId(Tools.get32UUID());
        }
        if(fireCheckListE.getCorpinfoId() == null){
            fireCheckListE.setCorpinfoId(AuthContext.getTenantId());
        }
        FireCheckListDO d = new FireCheckListDO();
        BeanUtils.copyProperties(fireCheckListE, d);
        fireCheckListRepository.save(d);
        fireCheckListE.setId(d.getId());
        return true;
    }

    @Override
    public Boolean update(FireCheckListE fireCheckListE) {
        FireCheckListDO d = new FireCheckListDO();
        BeanUtils.copyProperties(fireCheckListE, d);
        fireCheckListRepository.updateById(d);
        return true;
    }

    @Override
    public Boolean deletedFireCheckListById(Long id) {
        return fireCheckListRepository.removeById(id);
    }

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

