package com.zcloud.personnel.positioning.gatewayimpl;

import com.zcloud.personnel.positioning.domain.gateway.AlarmRuleItemGateway;
import com.zcloud.personnel.positioning.domain.model.AlarmRuleItemE;
import com.zcloud.personnel.positioning.persistence.dataobject.AlarmRuleItemDO;
import com.zcloud.personnel.positioning.persistence.repository.AlarmRuleItemRepository;
import lombok.AllArgsConstructor;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import java.util.Arrays;

/**
 * web-infrastructure
 *
 * @Author fangjiakai
 * @Date 2026-07-07
 */
@Service
@AllArgsConstructor
public class AlarmRuleItemGatewayImpl implements AlarmRuleItemGateway {
    private final AlarmRuleItemRepository alarmRuleItemRepository;

    @Override
    public Boolean add(AlarmRuleItemE alarmRuleItemE) {
        AlarmRuleItemDO dataObject = new AlarmRuleItemDO();
        BeanUtils.copyProperties(alarmRuleItemE, dataObject);
        alarmRuleItemRepository.save(dataObject);
        return true;
    }

    @Override
    public Boolean update(AlarmRuleItemE alarmRuleItemE) {
        AlarmRuleItemDO dataObject = new AlarmRuleItemDO();
        BeanUtils.copyProperties(alarmRuleItemE, dataObject);
        alarmRuleItemRepository.updateById(dataObject);
        return true;
    }

    @Override
    public Boolean deletedAlarmRuleItemById(Long id) {
        return alarmRuleItemRepository.removeById(id);
    }

    @Override
    public Boolean deletedAlarmRuleItemByIds(Long[] ids) {
        return alarmRuleItemRepository.removeByIds(Arrays.asList(ids));
    }
}
