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

namespace CncService.Impl
{
    /// <summary>
    /// 采集日志相关的业务实现
    /// </summary>
    public class CollectLogService : ICollectLogService
    {
        private readonly ICollectAnalysisRepository _analysisRepository;
        private readonly ICollectCycleRepository _cycleRepository;

        public CollectLogService(ICollectAnalysisRepository analysisRepository, ICollectCycleRepository cycleRepository)
        {
            _analysisRepository = analysisRepository ?? throw new ArgumentNullException(nameof(analysisRepository));
            _cycleRepository = cycleRepository ?? throw new ArgumentNullException(nameof(cycleRepository));
        }

        public PagedResult<CollectAnalysisListItem> GetAnalysisList(CollectAnalysisQuery query)
        {
            if (query == null) throw new BusinessException(ErrorCode.BadRequest, "查询参数不能为空");
            return _analysisRepository.GetAnalysisList(query);
        }

        public CollectAnalysisDetail GetAnalysisDetail(long id)
        {
            var detail = _analysisRepository.GetAnalysisDetail(id);
            if (detail == null) throw new BusinessException(ErrorCode.NotFound, "采集分析记录不存在");
            return detail;
        }

        public List<CollectAnalysisListItem> GetAnalysisByRawLogId(long rawLogId)
        {
            return _analysisRepository.GetAnalysisByRawLogId(rawLogId);
        }

        public PagedResult<CollectCycleListItem> GetCycleList(CollectCycleQuery query)
        {
            if (query == null) throw new BusinessException(ErrorCode.BadRequest, "查询参数不能为空");
            return _cycleRepository.GetCycleList(query);
        }
    }
}
