package com.zcloud.fire.check.gatewayimpl;

import com.jjb.saas.framework.auth.utils.AuthContext;
import com.zcloud.fire.check.domain.gateway.FireCheckListItemGateway;
import com.zcloud.fire.check.domain.model.FireCheckListItemE;
import com.zcloud.fire.check.persistence.dataobject.FireCheckListItemDO;
import com.zcloud.fire.check.persistence.repository.FireCheckListItemRepository;
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.List;
import java.util.stream.Collectors;

/**
 * web-infrastructure
 *
 * @Author zhaokai
 * @Date 2025-12-22 13:58:46
 */
@Service
@AllArgsConstructor
public class FireCheckListItemGatewayImpl implements FireCheckListItemGateway {
    private final FireCheckListItemRepository fireCheckListItemRepository;

    @Override
    public Boolean add(FireCheckListItemE fireCheckListItemE) {
        if(StringUtils.isEmpty(fireCheckListItemE.getFireCheckListItemId())){
            fireCheckListItemE.setFireCheckListItemId(Tools.get32UUID());
        }
        if(fireCheckListItemE.getCorpinfoId() == null){
            fireCheckListItemE.setCorpinfoId(AuthContext.getTenantId());
        }
        FireCheckListItemDO d = new FireCheckListItemDO();
        BeanUtils.copyProperties(fireCheckListItemE, d);
        fireCheckListItemRepository.save(d);
        return true;
    }

    @Override
    public Boolean update(FireCheckListItemE fireCheckListItemE) {
        FireCheckListItemDO d = new FireCheckListItemDO();
        BeanUtils.copyProperties(fireCheckListItemE, d);
        fireCheckListItemRepository.updateById(d);
        return true;
    }

    @Override
    public Boolean deletedFireCheckListItemById(Long id) {
        return fireCheckListItemRepository.removeById(id);
    }

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

