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

namespace Topsdk.Top.Ability3197;


public class Ability3197
{

    private ITopApiClient topApiClient;

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

    /*
        淘宝客-推广者-定向活动目标发布
        taobao.tbk.rta.consumer.match
    */
    public TaobaoTbkRtaConsumerMatchResponse TaobaoTbkRtaConsumerMatch(TaobaoTbkRtaConsumerMatchRequest request)
    {
        var jsonResult = topApiClient.Execute(request.GetApiCode(),request.ToRequestParam(),request.ToFileParam());
        if (string.IsNullOrEmpty(jsonResult))
        {
            throw new Exception("error");
        }
        var resultObj = TopUtils.parseResultJson<TaobaoTbkRtaConsumerMatchResponse>(jsonResult);
        if(string.IsNullOrEmpty(resultObj.Body))
        {
            resultObj.Body = jsonResult;
        }
        return resultObj;
    }

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