using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using System.Web.Script.Serialization;

namespace ZionRobot.WebService
{
    public class Lawsuit
    {
        internal List<Models.ZFlow.Lawsuit> LawsuitsToSync()
        {
            string result = new ZionVault.WebService.Client(Persistence.WSProperties.UrlApi)._request("GET",
                Persistence.WSProperties.LawsuitsToSync,
                Persistence.WSProperties.Token,
                null,
                string.Empty,
                null); 
            

            var json = JsonConvert.DeserializeObject<List<Models.ZFlow.Lawsuit>>(result);

            return json;
        }
        internal string UpdateUrl(Models.ZFlow.Lawsuit lawsuit)
        {
            var a = new JavaScriptSerializer().Serialize(new
            {
                lawsuit
            });
            return new ZionVault.WebService.Client(Persistence.WSProperties.UrlApi)._request("PUT",
                Persistence.WSProperties.UpdateLawsuitLink,
                Persistence.WSProperties.Token,
                null,
                a
                ,
                null);
        }
        internal string UpdateSync(Models.ZFlow.Lawsuit lawsuit, int status)
        {
            return new ZionVault.WebService.Client(Persistence.WSProperties.UrlApi)._request("PUT",
                Persistence.WSProperties.UpdateLawsuitSync,
                Persistence.WSProperties.Token,
                null,
                new JavaScriptSerializer().Serialize(new
                {
                    EntityId = lawsuit.EntityId,
                    ClientId = lawsuit.ClientId,
                    FieldOfLawId = lawsuit.FieldOfLawId,
                    Id = lawsuit.Id,
                    SyncId = lawsuit.SyncId,
                    SyncStatus = status
                }),
                null);
        }
    }
}
