using BO.BO;
using Forks.JsonRpc.Client;
using Forks.JsonRpc.Client.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Script.Serialization;

namespace BO.Utils
{
  public static class BaseInfoRpcUtil
  {
    static JavaScriptSerializer serializer = new JavaScriptSerializer();

    public static List<Tuple<string, string>> GetBaseInfoEntity(string rpcName)
    {
      var list = RpcFacade.Call<List<RpcObject>>(string.Format("/MainSystem/B3ClientService/Rpcs/BaseInfoRpc/{0}", rpcName), null, null, -1);
      var result = new List<Tuple<string, string>>();
      foreach (RpcObject o in list)
      {
        var entity = new Tuple<string, string>(o.Get<string>("PhyName"), o.Get<string>("DisplayName"));
        result.Add(entity);
      }
      return result;
    }

    public static List<Tuple<long, long, string>> GetSanctionList()
    {
      var list = RpcFacade.Call<List<RpcObject>>("/MainSystem/B3ClientService/Rpcs/BaseInfoRpc/GetSanctionList");
      var result = new List<Tuple<long, long, string>>();
      foreach (RpcObject o in list)
      {
        var entity = new Tuple<long, long, string>(o.Get<long>("ID"), o.Get<long>("AbnormalItem_ID"), o.Get<string>("AbnormalItem_Name"));
        result.Add(entity);
      }
      return result;
    }

    public static List<CTuple<long, string, short>> GetLivestockList()
    {
      var list = RpcFacade.Call<string>("/MainSystem/B3ClientService/Rpcs/BaseInfoRpc/GetLivestock");
      return serializer.Deserialize<List<CTuple<long, string, short>>>(list);
    }
  }
}
