using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Threading.Tasks;
using static System.Net.WebRequestMethods;

namespace EasyDevCore.Remote.HttpAccess
{
    /// <summary>
    /// Contract for serializing and deserializing objects.
    /// </summary>
    public interface ISerializer
    {
        /// <summary>
        /// Serializes an object to a string representation.
        /// </summary>
        string Serialize(object obj);
        /// <summary>
        /// Serializes the specified object.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="obj">The object.</param>
        /// <returns></returns>
        string Serialize<T>(T obj);
        /// <summary>
        /// Deserializes an object from a string representation.
        /// </summary>
        T Deserialize<T>(string s);
        /// <summary>
        /// Deserializes an object from a stream representation.
        /// </summary>
        T Deserialize<T>(Stream stream);
        /// <summary>
        /// Deserializes the asynchronous.
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="stream">The stream.</param>
        /// <returns></returns>
        Task<T> DeserializeAsync<T>(Stream stream);
    }

    /// <summary>
    /// 
    /// </summary>
    public class HttpAccessSetup
    {
        private static ISerializer _JsonSerializerRequest;
        private static ISerializer _UrlEncodedSerializerRequest;
        private static ISerializer _JsonSerializerResponse;

        /// <summary>
        /// Gets or sets the json serializer request.
        /// </summary>
        /// <value>
        /// The json serializer request.
        /// </value>
        public static ISerializer JsonSerializerRequest { get => (_JsonSerializerRequest ?? (_JsonSerializerRequest = new TextJsonSerializer())); set => _JsonSerializerRequest = value; }

        /// <summary>
        /// Gets or sets the URL encoded serializer.
        /// </summary>
        /// <value>
        /// The URL encoded serializer.
        /// </value>
        public static ISerializer UrlEncodedSerializerRequest { get => (_UrlEncodedSerializerRequest ?? (_UrlEncodedSerializerRequest = new UrlEncodedSerializer())); set => _UrlEncodedSerializerRequest = value; }

        /// <summary>
        /// Gets or sets the json serializer response.
        /// </summary>
        /// <value>
        /// The json serializer response.
        /// </value>
        public static ISerializer JsonSerializerResponse { get => (_JsonSerializerResponse ?? (_JsonSerializerResponse = new TextJsonSerializer())); set => _JsonSerializerResponse = value; }
    }
}
