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

namespace XYY.Service.Standard.ChannelApi.HuoYing
{
    public class CommonDataDetailsItem
    {
        /// <summary>
        /// 
        /// </summary>
        public string valueot { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string valuecode { get; set; }
        /// <summary>
        /// 北爱尔兰
        /// </summary>
        public string valuenm { get; set; }
    }

    public class CommonDataBody
    {
        /// <summary>
        /// 
        /// </summary>
        public string typeno { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public List<CommonDataDetailsItem> details { get; set; }
    }

    public class CommonData
    {
        /// <summary>
        /// 
        /// </summary>
        public int code { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public CommonDataBody data { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string msg { get; set; }
    }
    public class CommonDataRequst
    {
        /// <summary>
        /// 
        /// </summary>
        public string FACTNO { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string SUPNO { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string SUPPASS { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string APPKEY { get; set; }
        /// <summary>
        /// 
        /// </summary>
        public string TYPENO { get; set; }
    }

    public static class GetCommonData
    {
        #region 通用数据 json
        private static string STOCK = @"{
    ""code"": 1,
    ""data"": {
        ""typeno"": ""STOCK"",
        ""details"": [
            {
                ""rlyu"": 0,
                ""rongliang"": 0.0000,
                ""stocknm"": ""坂田仓"",
                ""pol"": ""001"",
                ""branch"": ""003-001"",
                ""stockno"": ""003001""
            },
            {
                ""rlyu"": 0,
                ""rongliang"": 0.0000,
                ""stocknm"": ""义乌仓"",
                ""pol"": ""306"",
                ""branch"": ""003-001"",
                ""stockno"": ""003002""
            }
        ]
    },
    ""msg"": ""success""
}";
        private static string BAOGUAN = @"{
    ""code"": 1,
    ""data"": {
        ""typeno"": ""BAOGUAN"",
        ""details"": [
            {
                ""valuecode"": ""01"",
                ""valuenm"": ""单证报关""
            },
            {
                ""valuecode"": ""02"",
                ""valuenm"": ""买单报关""
            },
            {
                ""valuecode"": ""03"",
                ""valuenm"": "" ""
            },
            {
                ""valuecode"": ""04"",
                ""valuenm"": ""合并单独报关""
            }
        ]
    },
    ""msg"": ""success""
}";
        #endregion

        /// <summary>
        /// 收货仓数据
        /// 国内不交货给他们，随便填一个
        /// </summary>
        /// <returns></returns>
        public static List<CommonDataDetailsItem> _getSTOCK()
        {
            return JsonConvert.DeserializeObject<CommonData>(STOCK).data.details;
        }
        /// <summary>
        /// 报关数据
        /// </summary>
        /// <returns></returns>
        public static CommonDataDetailsItem _getBAOGUAN(string valuenm)
        {
            var data = JsonConvert.DeserializeObject<CommonData>(BAOGUAN).data.details;
            CommonDataDetailsItem result = data.Where(x => x.valuenm == valuenm)?.FirstOrDefault();
            if (result == null) { throw new Exception($"【{valuenm}】没有匹配的报关方式！"); }
            return result;
        }

    }
}
