using System;
using System.Collections.Generic;
using System.Xml.Serialization;
using Top.Api;
using Top.Api.Util;

namespace Top.Api.Request
{
    /// <summary>
    /// TOP API: taobao.tbk.dg.smart.assistant.link.convert
    /// </summary>
    public class TbkDgSmartAssistantLinkConvertRequest : BaseTopRequest<Top.Api.Response.TbkDgSmartAssistantLinkConvertResponse>
    {
        /// <summary>
        /// 推广位id，mm_xx_xx_xx pid三段式中的第三段
        /// </summary>
        public long? AdzoneId { get; set; }

        /// <summary>
        /// 设备信息
        /// </summary>
        public string DeviceDto { get; set; } = string.Empty;

        public DeviceDtoDomain DeviceDto_ { set { DeviceDto = TopUtils.ObjectToJson(value); } }

        /// <summary>
        /// 导购商品流
        /// </summary>
        public string ItemFeedDto { get; set; } = "{}";

        public ItemFeedDtoDomain ItemFeedDto_ { set { ItemFeedDto = TopUtils.ObjectToJson(value); } }

        /// <summary>
        /// 原始商品链接
        /// </summary>
        public string OriginalItemUrl { get; set; } = string.Empty;

        /// <summary>
        /// 三方pid，满足mm_xxx_xxx_xxx格式
        /// </summary>
        public string SubPid { get; set; } = string.Empty;

        /// <summary>
        /// 同款商品
        /// </summary>
        public string TargetItemDto { get; set; } = "{}";

        public TargetItemDtoDomain TargetItemDto_ { set { TargetItemDto = TopUtils.ObjectToJson(value); } }

        public override string GetApiName()
        {
            return "taobao.tbk.dg.smart.assistant.link.convert";
        }

        public override IDictionary<string, string> GetParameters()
        {
            TopDictionary parameters = new();
            parameters.Add("adzone_id", AdzoneId?.ToString());
            parameters.Add("device_dto", DeviceDto);
            parameters.Add("item_feed_dto", ItemFeedDto);
            parameters.Add("original_item_url", OriginalItemUrl);
            parameters.Add("sub_pid", SubPid);
            parameters.Add("target_item_dto", TargetItemDto);

            return parameters;
        }

        public override void Validate()
        {
            RequestValidator.ValidateRequired("adzone_id", AdzoneId);
            RequestValidator.ValidateRequired("device_dto", DeviceDto);
            RequestValidator.ValidateRequired("item_feed_dto", ItemFeedDto);
            RequestValidator.ValidateRequired("original_item_url", OriginalItemUrl);
            RequestValidator.ValidateRequired("sub_pid", SubPid);
            RequestValidator.ValidateRequired("target_item_dto", TargetItemDto);
        }

        [Serializable]
        public class DeviceDtoDomain : TopObject
        {
            /// <summary>
            /// 设备ID MD5值
            /// </summary>
            [XmlElement("device_id")]
            public string DeviceId { get; set; } = string.Empty;

            /// <summary>
            /// 支持OAID_MD5，IDFA_MD5
            /// </summary>
            [XmlElement("device_type")]
            public string DeviceType { get; set; } = string.Empty;
        }

        [Serializable]
        public class ItemFeedDtoDomain : TopObject
        {
            /// <summary>
            /// 商品ID列表，最多10个
            /// </summary>
            [XmlArray("item_feed_list")]
            [XmlArrayItem("string")]
            public List<string>? ItemFeedList { get; set; }

            /// <summary>
            /// 转链类型,1-单品 2-会场定坑
            /// </summary>
            [XmlElement("link_transfer_type")]
            public long? LinkTransferType { get; set; }

            /// <summary>
            /// 定坑会场ID
            /// </summary>
            [XmlElement("page_id")]
            public string? PageId { get; set; }
        }

        [Serializable]
        public class TargetItemDtoDomain : TopObject
        {
            /// <summary>
            /// 商品ID，未入参联盟补齐
            /// </summary>
            [XmlElement("item_id")]
            public string? ItemId { get; set; }

            /// <summary>
            /// 转链类型,1-单品 2-会场定坑
            /// </summary>
            [XmlElement("link_transfer_type")]
            public long? LinkTransferType { get; set; }

            /// <summary>
            /// 定坑会场ID
            /// </summary>
            [XmlElement("page_id")]
            public string? PageId { get; set; }
        }
    }
}

namespace Top.Api.Response
{
    /// <summary>
    /// TbkDgSmartAssistantLinkConvertResponse.
    /// </summary>
    public class TbkDgSmartAssistantLinkConvertResponse : TopResponse
    {
        /// <summary>
        /// 转链结果
        /// </summary>
        [XmlElement("data")]
        public SmartAssertLinkResultDomain? Data { get; set; }

        [Serializable]
        public class SmartAssertLinkResultDomain : TopObject
        {
            /// <summary>
            /// 不返回导购会场原因
            /// </summary>
            [XmlElement("msg")]
            public string Msg { get; set; } = string.Empty;

            /// <summary>
            /// 进行校验后输出的导购会场deeplink
            /// </summary>
            [XmlElement("page_deeplink")]
            public string PageDeeplink { get; set; } = string.Empty;
        }
    }
}
