using System.Text;
using dodohold.core;
using System.Text.RegularExpressions;
using System.Net;
using System.Security.Cryptography;
using TencentCloud.Ecm.V20190719.Models;

namespace molilian.core
{
    public partial class AlimamaPlus
    {
        internal static string FakeItemUrl(string content, string dplink)
        {
            if (string.IsNullOrEmpty(content))
            {
                content = dplink.Replace("taobao://", "https://");
            }
            (bool success, string url) = IsTaobaoUrl(content);
            if (success) return url;
            return content;
        }

        internal async Task<UnionCouponDTO> UnionCoupon2Async(string content, UnionCouponDTO result, CancellationToken cancellationToken = default)
        {
            TkDataDTO data = new();
            data = await alimamaParseAsync(content, data, cancellationToken);

            result.channel = data.channel;
            result.success = data.success;
            result.reason = data.reason;
            result.message = data.success ? "OK" : data.message;

            if (result.success)
            {
                if (data.couponAmount == 0)
                {
                    result.success = false;
                    result.message = "没有优惠券";
                    result.reason = "";
                    result.deeplink_url = string.Empty;
                }
                else
                {
                    result.deeplink_url = data.deeplink_url;
                    result.couponAmount = data.couponAmount;
                    result.couponEffectiveStartTime = data.couponEffectiveStartTime;
                    result.couponEffectiveEndTime = data.couponEffectiveEndTime;
                    result.itemId = data.itemId;
                    result.pic = data.pic;
                }
            }




            //public bool success { get; set; } = false;
            //public string reason { get; set; } = string.Empty;
            //public string message { get; set; } = string.Empty;
            //public string deeplink_url { get; set; } = string.Empty;
            //public int elapsedTime { get; set; } = 0;
            //public string ip { get; set; } = string.Empty;
            //public string oaid { get; set; } = string.Empty;
            //public decimal couponAmount { get; set; } = 0.00M;
            //public string itemId { get; set; } = string.Empty;
            //public string pic { get; set; } = string.Empty;
            //public DateTime create_time { get; set; } = DateTime.Now;
            return result;
        }


    }
}
