package com.zcloud.personnel.positioning.gatewayimpl;

import com.zcloud.personnel.positioning.domain.gateway.AlarmRuleGateway;
import com.zcloud.personnel.positioning.domain.model.AlarmRuleE;
import com.zcloud.personnel.positioning.persistence.dataobject.AlarmRuleDO;
import com.zcloud.personnel.positioning.persistence.repository.AlarmRuleRepository;
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 AlarmRuleGatewayImpl implements AlarmRuleGateway {
    private final AlarmRuleRepository alarmRuleRepository;

    @Override
    public Boolean add(AlarmRuleE alarmRuleE) {
        AlarmRuleDO dataObject = new AlarmRuleDO();
        BeanUtils.copyProperties(alarmRuleE, dataObject);
        alarmRuleRepository.save(dataObject);
        return true;
    }

    @Override
    public Boolean update(AlarmRuleE alarmRuleE) {
        AlarmRuleDO dataObject = new AlarmRuleDO();
        BeanUtils.copyProperties(alarmRuleE, dataObject);
        alarmRuleRepository.updateById(dataObject);
        return true;
    }

    @Override
    public Boolean deletedAlarmRuleById(Long id) {
        return alarmRuleRepository.removeById(id);
    }

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