using System;
using System.Collections.Generic;
using System.Text.Json.Serialization;
using BO.ProcessServer.Business.Enums;

namespace BO.ProcessServer.Options
{
    internal class Configuration
    {
        [JsonPropertyName("api-base-url")] public Uri ApiBaseUrl { get; set; }
        [JsonPropertyName("api-user")] public string ApiUser { get; set; }
        [JsonPropertyName("api-pwd")] public string ApiUserPwd { get; set; }
        [JsonPropertyName("api-magic")] public string ApiMagic { get; set; }
        [JsonPropertyName("api-timeout")] public string ApiTimeoutRaw { get; set; }
        public TimeSpan ApiTimeout => TimeSpan.Parse(ApiTimeoutRaw);

        public CfgSystem System { get; set; }
        public class CfgSystem
        {
            [JsonPropertyName("mode")]  public AppModeEnum Mode { get; set; }
            [JsonPropertyName("identification")] public string Identification { get; set; }
            [JsonPropertyName("preferred-interface")] public string PreferredInterface { get; set; }
            [JsonPropertyName("pool-pull-documents")] public int PoolPullDocuments { get; set; }
            [JsonPropertyName("pool-pull-interval")] public string PoolPullIntervalRaw { get; set; }
            public TimeSpan PoolPullInterval => TimeSpan.Parse(PoolPullIntervalRaw);
            [JsonPropertyName("pool-path-base")] public string PoolPathBase { get; set; }
            [JsonPropertyName("pool-path-pending")] public string PoolPathPending { get; set; }
            [JsonPropertyName("pool-path-working")] public string PoolPathWorking { get; set; }
            [JsonPropertyName("pool-path-done")] public string PoolPathDone { get; set; }
            [JsonPropertyName("pool-path-fail")] public string PoolPathFail { get; set; }
            [JsonPropertyName("pool-retention")] public CfgPoolRetention Retention { get; set; }
            [JsonPropertyName("status-monitoring")] public CfgStatusMonitoring Status { get; set; }
            [JsonPropertyName("scenario-path-base")] public string ScenarioPathBase { get; set; }
            [JsonPropertyName("scenario-parallels")] public int ScenarioParallelThreads { get; set; }
            [JsonPropertyName("scenarios")] public IEnumerable<CfgScenario> Scenarios { get; set; }
            [JsonPropertyName("proxy")] public CfgProxies Proxy { get; set; }
        }

        public class CfgScenarioAcceptFilter
        {
            [JsonPropertyName("code")] public string Code { get; set; }
            [JsonPropertyName("value")] public string Value { get; set; }
        }

        public class CfgScenario
        {
            [JsonPropertyName("name")] public string Name { get; set; }
            [JsonPropertyName("cmd")] public string ShellCommand { get; set; }
            [JsonPropertyName("args")] public string ShellCommandArguments { get; set; }
            [JsonPropertyName("accept-filters")] public IEnumerable<CfgScenarioAcceptFilter> AcceptFilters { get; set; }
            [JsonPropertyName("timeout-interval")] public string TimeoutIntervalRaw { get; set; }
            public TimeSpan TimeoutInterval => TimeSpan.Parse(TimeoutIntervalRaw);
            [JsonPropertyName("exitcode-succ")] public int ExitCodeSucc { get; set; }
            [JsonPropertyName("exitcode-fail")] public int ExitCodeFail { get; set; }
        }

        public class CfgStatusMonitoring
        {
            [JsonPropertyName("enabled")] public bool Enabled { get; set; }
            [JsonPropertyName("monitoring-interval")] public string IntervalRaw { get; set; }
            public TimeSpan Interval => TimeSpan.Parse(IntervalRaw);
            [JsonPropertyName("file")] public string File { get; set; }
        }

        public class CfgPoolRetention
        {
            [JsonPropertyName("enabled")] public bool Enabled { get; set; }
            [JsonPropertyName("retention-interval")] public string IntervalRaw { get; set; }
            public TimeSpan Interval => TimeSpan.Parse(IntervalRaw);
            [JsonPropertyName("size")] public long Size { get; set; }
            [JsonPropertyName("items")] public int Items { get; set; }
        }

        public class CfgProxies
        {
            [JsonPropertyName("process")] public CfgProxiesProcess Process { get; set; }
            [JsonPropertyName("app")] public CfgProxiesApp App { get; set; }
        }

        public class CfgProxiesProcess
        {
            [JsonPropertyName("succ")] public IEnumerable<bool> Succ { get; set; }
            [JsonPropertyName("output")]public IEnumerable<string> Output { get; set; }
        }

        public class CfgProxiesApp
        {
            [JsonPropertyName("default-documents-count")] public int DefaultDocumentsCount { get; set; }
            [JsonPropertyName("max-documents-count")] public int MaxDocumentsCount { get; set; }
            [JsonPropertyName("default-artifacts-count")] public int DefaultArtifactCount { get; set; }
            [JsonPropertyName("extension")] public IEnumerable<string> Extension { get; set; }
            [JsonPropertyName("nameprefix")] public IEnumerable<string> NameProfix { get; set; }
            [JsonPropertyName("presetcreditcost")] public IEnumerable<int> PresetCreditCost { get; set; }
            [JsonPropertyName("presetwatermark")] public IEnumerable<bool> PresetWatermark { get; set; }
            [JsonPropertyName("presetquality")] public IEnumerable<int> PresetQuality { get; set; }
            [JsonPropertyName("presetprocessprofile")] public IEnumerable<string> PresetProcessProfile { get; set; }
            [JsonPropertyName("presettest")] public IEnumerable<bool> PresetTest { get; set; }
        }
    }

}
