using System;
using System.Collections.Generic;
using CncService.Interface;
using CncModels.Dto.Alert;
using CncModels.Dto;
using CncModels.Constants;
using CncRepository.Interface;

namespace CncService.Impl
{
    /// <summary>
    /// 告警管理实现
    /// </summary>
    public class AlertService : IAlertService
    {
        private readonly IAlertRepository _alertRepository;

        public AlertService(IAlertRepository alertRepository)
        {
            _alertRepository = alertRepository ?? throw new ArgumentNullException(nameof(alertRepository));
        }

        /// <inheritdoc/>
        public PagedResult<AlertListItem> GetList(AlertQuery query)
        {
            if (query == null) throw new BusinessException(ErrorCode.BadRequest, "查询参数不能为空");
            return _alertRepository.GetList(query);
        }

        /// <inheritdoc/>
        public bool Resolve(long id)
        {
            if (id <= 0) throw new BusinessException(ErrorCode.BadRequest, "无效的告警ID");
            return _alertRepository.Resolve(id);
        }

        /// <inheritdoc/>
        public int BatchResolve(List<long> ids)
        {
            if (ids == null || ids.Count == 0) throw new BusinessException(ErrorCode.BadRequest, "无效的ID列表");
            return _alertRepository.BatchResolve(ids);
        }

        /// <inheritdoc/>
        public AlertStatisticsResponse GetStatistics()
        {
            return _alertRepository.GetStatistics();
        }
    }
}
