using System;
using System.Collections.Generic;
using System.Data.SqlClient;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Txgy.EWS.Client.IBLL;
using Txgy.EWS.Client.IDAL;
using Txgy.EWS.Client.Models;
using Txgy.Microseismic.BaseLib.Common;
using Txgy.Microseismic.BaseLib.Entitys;

namespace Txgy.EWS.Client.BLL
{
    public class SearchMsEventBLL : ISearchMsEventBLL
    {
        private readonly IRemoteMySQLDataAccess remoteMySQLDataAccess;
        
        public SearchMsEventBLL(IRemoteMySQLDataAccess remoteMySQLDataAccess)
        {
            this.remoteMySQLDataAccess = remoteMySQLDataAccess;
        }

        public int PreSelectCount { get => remoteMySQLDataAccess.PreSelectCount; set => remoteMySQLDataAccess.PreSelectCount = value; }

        public bool DownLoadWavedata(string eventTime, string savePath, string saveName, string tableName)
        {
            return remoteMySQLDataAccess.DownLoadWavedata(eventTime, savePath, saveName, tableName);
        }

        public List<MmEventEntity> GetEvents(DateTime startTime, DateTime endTime)
        {
            return remoteMySQLDataAccess.GetEvents(startTime, endTime);
        }

        public List<MmEventEntity> GetEvents(string QueryStr, SortTarget ssm, int sm, Models.FilterCondition<double> energyFC)
        {
            return remoteMySQLDataAccess.GetEvents(QueryStr, ssm,sm,energyFC);
        }

        public List<MmEventEntity> GetEvents(DateTime startTime, DateTime endTime, double minML, double maxML)
        {
            return remoteMySQLDataAccess.GetEvents(startTime, endTime, minML, maxML);
        }

        public MmEventEntity GetEvent(string eventTime)
        {
            return remoteMySQLDataAccess.GetEvent(eventTime);
        }

        public MmEventEntity GetEvent(int eventID)
        {
            return remoteMySQLDataAccess.GetEvent(eventID);
        }

        public List<postproeventresult> GetEvents(DateTime startTime, DateTime endTime, int pageIndex, int perPageCount, float minML, float maxML)
        {
            List<postproeventresult> res = remoteMySQLDataAccess.GetEvents(startTime, endTime, pageIndex, perPageCount, minML, maxML);

            return res;
        }
        public List<MmEventEntity> GetTopEvents(int MaxCnt, int PreCnt)
        {
            return remoteMySQLDataAccess.GetTopEvents(MaxCnt, PreCnt);
        }

        public void SaveBinaryFile(string fn, byte[] datas)
        {
            //throw new NotImplementedException();
        }

        public MmEventEntity GetLastEvent()
        {
            return remoteMySQLDataAccess.GetLastEvent();
        }

        public MmEventEntity GetLastEvent(DateTime deadline)
        {
            return remoteMySQLDataAccess.GetLastEvent(deadline);
        }

        public List<MmEventEntity> GetLastNewEvents(int resultCount)
        {
            return remoteMySQLDataAccess.GetLastNewEvents(resultCount);
        }
        public Task<int> StatEventCountAsync(DateTime startTime, DateTime endTime)
        {
            return remoteMySQLDataAccess.StatEventCountAsync(startTime, endTime);
        }

        public Task QueryAndDownloadDataAsync(int eventID, string savePath, Action<GridItemEventResult> callback)
        {
            return remoteMySQLDataAccess.QueryAndDownloadDataAsync(eventID, savePath, callback);
        }

        public Task QueryAndDownloadDataAsync(int eventID, DateTime endTime, string savePath, Action<GridItemEventResult> callback)
        {
            return remoteMySQLDataAccess.QueryAndDownloadDataAsync(eventID, endTime, savePath, callback);
        }

        public List<GridItemEventResult> GetLastTopEvents(int QueryCount)
        {
            return remoteMySQLDataAccess.GetLastTopEvents(QueryCount);
        }

        public ValueTask DownloadWaveDataAsync(GridItemEventResult gier, string savePath, Action<GridItemEventResult> callback)
        {
            return remoteMySQLDataAccess.DownloadWaveDataAsync(gier, savePath, callback);
        }

        public List<GridItemEventResult> GetGridEvents(DateTime startTime, DateTime endTime, double minML, double maxML)
        {
            return remoteMySQLDataAccess.GetGridEvents(startTime, endTime, minML, maxML);
        }

        public Task QueryEventByIDAsync(int eventID, string savePath, Action<GridItemEventResult> callback)
        {
            return remoteMySQLDataAccess.QueryEventByIDAsync(eventID, savePath, callback);
        }

        public ValueTask DownloadJsonDataAsync(GridItemEventResult gier, string savePath, Action<GridItemEventResult> callback)
        {
            return remoteMySQLDataAccess.DownloadJsonDataAsync(gier, savePath, callback);
        }

        public List<GridItemEventResult> GetLastEvents(int lastEventID)
        {
            return remoteMySQLDataAccess.GetLastEvents(lastEventID);
        }
    }
}
