using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Xml.Linq;

namespace HH.YiDaSyncNC.Models
{
    class KH_SyncServiceModel
    {
        public class DataModel
        {
            public string pk_group { get; set; }
            public string pk_org { get; set; }

            public string code { get; set; }
            public string name { get; set; }
            public string pk_custclass { get; set; }
            public string taxpayerid { get; set; }
            public string custprop { get; set; }

            public List<SuplinkmanItem> suplinkman { get; set; }

            public class SuplinkmanItem
            {
                public string name { get; set; }
                public string cell { get; set; }
                public string vjob { get; set; }
            }
        }

        public class ImportXml
        {
            /// <summary>
            /// 模板头部份
            /// </summary>
            /// <returns></returns>
            public static XElement TemplateHeade()
            {

                return new XElement(new XElement("ufinterface", new object[]
                {
                new XAttribute("sender","dingding"),
                new XAttribute("roottag",""),
                new XAttribute("replace","Y"),
                new XAttribute("isexchange","Y"),
                new XAttribute("groupcode","0"),
                new XAttribute("filename",""),
                new XAttribute("billtype","customer"),
                new XAttribute("proc","add"),
                new XAttribute("account","develop")
                }));
            }

            /// <summary>
            /// 组建表头xml
            /// </summary>
            /// <param name="item">表头参数</param>
            /// <returns></returns>
            public static XElement Header(DataModel item, string id)
            {
                var suplinkmanList = new List<XElement>();

                if (item.suplinkman != null && item.suplinkman.Count > 0)
                {
                    foreach (var itemData in item.suplinkman)
                    {
                        suplinkmanList.Add(new XElement("item", new object[] {
                            new XElement("linkmanvo",new object[]{
                                new XElement("name",itemData.name),
                                new XElement("cell",itemData.cell),
                                new XElement("vjob",itemData.vjob),
                            }),
                            new XElement("pk_linkman",""),
                            new XElement("isdefault","N"),
                        }));
                    }
                }

                return new XElement("bill", new object[]
                {
                "",
                new XAttribute("id",id),
                new XElement("billhead", new object[]
                {
                    new XElement("pk_group",item.pk_group),
                    new XElement("pk_org",item.pk_org),

                    new XElement("code",item.code),
                    new XElement("name",item.name),
                    new XElement("pk_custclass",item.pk_custclass),
                    new XElement("taxpayerid",item.taxpayerid),
                    new XElement("custprop",item.custprop),

                    new XElement("custcontacts",suplinkmanList),

                    new XElement("pk_country","CN"),
                    new XElement("pk_timezone","P0800"),
                    new XElement("pk_format","ZH-CN"),
                }),
                });
            }
        }
    }
}
