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

namespace Topsdk.Top.Ability376;


public class Ability376
{

    private ITopApiClient topApiClient;

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

    /*
        淘宝客-公用-长链转短链
        taobao.tbk.spread.get
    */
    public TaobaoTbkSpreadGetResponse TaobaoTbkSpreadGet(TaobaoTbkSpreadGetRequest request)
    {
        var jsonResult = topApiClient.Execute(request.GetApiCode(),request.ToRequestParam(),request.ToFileParam());
        if (string.IsNullOrEmpty(jsonResult))
        {
            throw new Exception("error");
        }
        var resultObj = TopUtils.parseResultJson<TaobaoTbkSpreadGetResponse>(jsonResult);
        if(string.IsNullOrEmpty(resultObj.Body))
        {
            resultObj.Body = jsonResult;
        }
        return resultObj;
    }

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