using DataSharing.Share.Dtos.Province;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace DataSharing.Province
{
    public class ProvinceRequest<TData> : ProvinceRequest
    {
        [JsonPropertyName("paras")]
        public TData Data { get; set; }

        public void SetData(TData data)
        {
            Data = data;
        }

        public ProvinceRequest(string clientId, string clientSecret) : base(clientId, clientSecret)
        {
        }

        public ProvinceRequest(ClientInfo clientInfo) : base(clientInfo)
        {
        }

        public override string ToString() => JsonSerializer.Serialize(this, ProvinceJsonSerializerOptions.UnStandardDatetimeJsonOptions);
    }

    public class ProvinceListRequest<TData> : ProvinceRequest
    {
        [JsonPropertyName("paras")]
        public RequestItem Data { get; set; }

        public void SetData(List<TData> items)
        {
            Data = new RequestItem
            {
                Items = items
            };
        }

        public ProvinceListRequest(string clientId, string clientSecret) : base(clientId, clientSecret)
        {
        }

        public ProvinceListRequest(ClientInfo clientInfo) : base(clientInfo)
        {
        }

        public class RequestItem
        {
            [JsonPropertyName("jsonList")]
            public List<TData> Items { get; set; }
        }

        public override string ToString() => JsonSerializer.Serialize(this, ProvinceJsonSerializerOptions.UnStandardDatetimeJsonOptions);
    }

    public abstract class ProvinceRequest
    {
        public ProvinceRequest(string clientId, string clientSecret)
        {
            ClientInfo = new ClientInfo(clientId, clientSecret);
        }

        public ProvinceRequest(ClientInfo clientInfo)
        {
            ClientInfo = clientInfo;
        }

        [JsonPropertyName("token")]
        public ClientInfo ClientInfo { get; set; }
    }
}
