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

namespace Topsdk.Top.Ability3261;


public class Ability3261
{

    private ITopApiClient topApiClient;

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

    /*
        淘宝客-推广者-CPA活动执行明细
        taobao.tbk.dg.cpa.activity.detail
    */
    public TaobaoTbkDgCpaActivityDetailResponse TaobaoTbkDgCpaActivityDetail(TaobaoTbkDgCpaActivityDetailRequest request)
    {
        var jsonResult = topApiClient.Execute(request.GetApiCode(),request.ToRequestParam(),request.ToFileParam());
        if (string.IsNullOrEmpty(jsonResult))
        {
            throw new Exception("error");
        }
        var resultObj = TopUtils.parseResultJson<TaobaoTbkDgCpaActivityDetailResponse>(jsonResult);
        if(string.IsNullOrEmpty(resultObj.Body))
        {
            resultObj.Body = jsonResult;
        }
        return resultObj;
    }
    /*
        淘宝客-推广者-任务奖励效果报表
        taobao.tbk.dg.cpa.activity.report
    */
    public TaobaoTbkDgCpaActivityReportResponse TaobaoTbkDgCpaActivityReport(TaobaoTbkDgCpaActivityReportRequest request)
    {
        var jsonResult = topApiClient.Execute(request.GetApiCode(),request.ToRequestParam(),request.ToFileParam());
        if (string.IsNullOrEmpty(jsonResult))
        {
            throw new Exception("error");
        }
        var resultObj = TopUtils.parseResultJson<TaobaoTbkDgCpaActivityReportResponse>(jsonResult);
        if(string.IsNullOrEmpty(resultObj.Body))
        {
            resultObj.Body = jsonResult;
        }
        return resultObj;
    }

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