using Topsdk.Top.Ability371.Request;
using Topsdk.Top.Ability371.Response;
using Topsdk.Util;

namespace Topsdk.Top.Ability371;


public class Ability371
{

    private ITopApiClient topApiClient;

    public Ability371(ITopApiClient topApiClient)
    {
        this.topApiClient = topApiClient;
    }

    /*
        淘宝客-公用-阿里妈妈推广券详情查询
        taobao.tbk.coupon.get
    */
    public TaobaoTbkCouponGetResponse TaobaoTbkCouponGet(TaobaoTbkCouponGetRequest request)
    {
        var jsonResult = topApiClient.Execute(request.GetApiCode(),request.ToRequestParam(),request.ToFileParam());
        if (string.IsNullOrEmpty(jsonResult))
        {
            throw new Exception("error");
        }
        var resultObj = TopUtils.parseResultJson<TaobaoTbkCouponGetResponse>(jsonResult);
        if(string.IsNullOrEmpty(resultObj.Body))
        {
            resultObj.Body = jsonResult;
        }
        return resultObj;
    }
    /*
        淘宝客-公用-淘宝客商品详情查询(简版)
        taobao.tbk.item.info.get
    */
    public TaobaoTbkItemInfoGetResponse TaobaoTbkItemInfoGet(TaobaoTbkItemInfoGetRequest request)
    {
        var jsonResult = topApiClient.Execute(request.GetApiCode(),request.ToRequestParam(),request.ToFileParam());
        if (string.IsNullOrEmpty(jsonResult))
        {
            throw new Exception("error");
        }
        var resultObj = TopUtils.parseResultJson<TaobaoTbkItemInfoGetResponse>(jsonResult);
        if(string.IsNullOrEmpty(resultObj.Body))
        {
            resultObj.Body = jsonResult;
        }
        return resultObj;
    }
    /*
        淘宝客商品详情查询（简版）（临时接口）
        taobao.tbk.item.info.temporary.get
    */
    public TaobaoTbkItemInfoTemporaryGetResponse TaobaoTbkItemInfoTemporaryGet(TaobaoTbkItemInfoTemporaryGetRequest request)
    {
        var jsonResult = topApiClient.Execute(request.GetApiCode(),request.ToRequestParam(),request.ToFileParam());
        if (string.IsNullOrEmpty(jsonResult))
        {
            throw new Exception("error");
        }
        var resultObj = TopUtils.parseResultJson<TaobaoTbkItemInfoTemporaryGetResponse>(jsonResult);
        if(string.IsNullOrEmpty(resultObj.Body))
        {
            resultObj.Body = jsonResult;
        }
        return resultObj;
    }
    /*
        淘宝客-公用-淘宝客商品详情查询升级版（简易版）
        taobao.tbk.item.info.upgrade.get
    */
    public TaobaoTbkItemInfoUpgradeGetResponse TaobaoTbkItemInfoUpgradeGet(TaobaoTbkItemInfoUpgradeGetRequest request)
    {
        var jsonResult = topApiClient.Execute(request.GetApiCode(),request.ToRequestParam(),request.ToFileParam());
        if (string.IsNullOrEmpty(jsonResult))
        {
            throw new Exception("error");
        }
        var resultObj = TopUtils.parseResultJson<TaobaoTbkItemInfoUpgradeGetResponse>(jsonResult);
        if(string.IsNullOrEmpty(resultObj.Body))
        {
            resultObj.Body = jsonResult;
        }
        return resultObj;
    }

    public ITopApiClient TopApiClient
    {
        get => topApiClient;
        set => topApiClient = value ?? throw new ArgumentNullException(nameof(value));
    }
}
