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

namespace Topsdk.Top.Ability414;


public class Ability414
{

    private ITopApiClient topApiClient;

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

    /*
        淘宝客-推广者-全量售后退款订单查询
        taobao.tbk.order.refund.get
    */
    public TaobaoTbkOrderRefundGetResponse TaobaoTbkOrderRefundGet(TaobaoTbkOrderRefundGetRequest request)
    {
        var jsonResult = topApiClient.Execute(request.GetApiCode(),request.ToRequestParam(),request.ToFileParam());
        if (string.IsNullOrEmpty(jsonResult))
        {
            throw new Exception("error");
        }
        var resultObj = TopUtils.parseResultJson<TaobaoTbkOrderRefundGetResponse>(jsonResult);
        if(string.IsNullOrEmpty(resultObj.Body))
        {
            resultObj.Body = jsonResult;
        }
        return resultObj;
    }
    /*
        淘宝客-推广者-售后退款订单查询
        taobao.tbk.relation.refund
    */
    public TaobaoTbkRelationRefundResponse TaobaoTbkRelationRefund(TaobaoTbkRelationRefundRequest request)
    {
        var jsonResult = topApiClient.Execute(request.GetApiCode(),request.ToRequestParam(),request.ToFileParam());
        if (string.IsNullOrEmpty(jsonResult))
        {
            throw new Exception("error");
        }
        var resultObj = TopUtils.parseResultJson<TaobaoTbkRelationRefundResponse>(jsonResult);
        if(string.IsNullOrEmpty(resultObj.Body))
        {
            resultObj.Body = jsonResult;
        }
        return resultObj;
    }
    /*
        淘宝客-推广者-所有订单查询
        taobao.tbk.order.details.get
    */
    public TaobaoTbkOrderDetailsGetResponse TaobaoTbkOrderDetailsGet(TaobaoTbkOrderDetailsGetRequest request)
    {
        var jsonResult = topApiClient.Execute(request.GetApiCode(),request.ToRequestParam(),request.ToFileParam());
        if (string.IsNullOrEmpty(jsonResult))
        {
            throw new Exception("error");
        }
        var resultObj = TopUtils.parseResultJson<TaobaoTbkOrderDetailsGetResponse>(jsonResult);
        if(string.IsNullOrEmpty(resultObj.Body))
        {
            resultObj.Body = jsonResult;
        }
        return resultObj;
    }
    /*
        淘宝客-推广者-所有订单查询（临时接口）
        taobao.tbk.order.details.temporary.get
    */
    public TaobaoTbkOrderDetailsTemporaryGetResponse TaobaoTbkOrderDetailsTemporaryGet(TaobaoTbkOrderDetailsTemporaryGetRequest request)
    {
        var jsonResult = topApiClient.Execute(request.GetApiCode(),request.ToRequestParam(),request.ToFileParam());
        if (string.IsNullOrEmpty(jsonResult))
        {
            throw new Exception("error");
        }
        var resultObj = TopUtils.parseResultJson<TaobaoTbkOrderDetailsTemporaryGetResponse>(jsonResult);
        if(string.IsNullOrEmpty(resultObj.Body))
        {
            resultObj.Body = jsonResult;
        }
        return resultObj;
    }

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