using Newtonsoft.Json;
using System;
using System.Collections.Generic;

namespace Txgy.EWS.Client.Common
{
    public class BusinessConfig
    {
        public EndpointSettings Endpoints { get; set; }
        public PathSettings Paths { get; set; }
        public RuntimeSettings Runtime { get; set; }
        public DatabaseSettings Database { get; set; }
        public BrandingSettings Branding { get; set; }
        public ReportSettings Report { get; set; }
        public CoordinateSettings Coordinates { get; set; }
    }

    public class EndpointSettings
    {
        public string ApiDomain { get; set; }
    }

    public class PathSettings
    {
        public string AlarmSetting { get; set; }
        public string AlarmLevelConfig { get; set; }
        public string ReportEventLevelSetting { get; set; }
        public string WorkAreaFilePath { get; set; }
        public string StationsCsvFilePath { get; set; }
        public string CadDwgFilePath { get; set; }
        public string DwgJsonSetting { get; set; }
        public string WavesMseedFilePath { get; set; }
        public string WavesTxtFilePath { get; set; }
        public string LocalSqLiteDb { get; set; }
        public string DwgSettings { get; set; }
        public string CadSettingsFileName { get; set; }
    }

    public class RuntimeSettings
    {
        public bool IsDesign { get; set; }
        public bool IsRealtime { get; set; }
        public int RefreshInterval { get; set; }
        public double DataLookbackHours { get; set; }

        [JsonIgnore]
        public int EventShowTotalSeconds => (int)Math.Round(DataLookbackHours * 3600.0);

        [JsonIgnore]
        public int LoadDataTimeLenMins => (int)Math.Round(DataLookbackHours * 60.0);

        public int DataCacheTimeLenMins { get; set; }
    }

    public class DatabaseSettings
    {
        public Dictionary<string, string> Connections { get; set; }
        public TableSettings Tables { get; set; }
    }

    public class TableSettings
    {
        public string RealtimeResultTable { get; set; }
        public string RealtimeWaveDataTable { get; set; }
        public string RealtimeFocalmechanismTable { get; set; }
        public string PostResultTable { get; set; }
        public string PostWaveDataTable { get; set; }
        public string PostFocalmechanismTable { get; set; }
    }

    public class BrandingSettings
    {
        public string CommpanyName { get; set; }
        public string SystemNameCn { get; set; }
        public string SystemNameEn { get; set; }
        public string WorkAreaName { get; set; }
        public string SystemShortName { get; set; }
    }

    public class ReportSettings
    {
        public string DailyReportStartTime { get; set; }
        public double DailyReportPlanOffsetX { get; set; }
        public double DailyReportPlanOffsetY { get; set; }
    }

    public class CoordinateSettings
    {
        public double BaseX { get; set; }
        public double BaseY { get; set; }
        public double BaseZ { get; set; }
    }
}
