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

namespace Topsdk.Top.Ability375;


public class Ability375
{

    private ITopApiClient topApiClient;

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

    /*
        淘宝客-公用-淘口令生成
        taobao.tbk.tpwd.create
    */
    public TaobaoTbkTpwdCreateResponse TaobaoTbkTpwdCreate(TaobaoTbkTpwdCreateRequest request)
    {
        var jsonResult = topApiClient.Execute(request.GetApiCode(),request.ToRequestParam(),request.ToFileParam());
        if (string.IsNullOrEmpty(jsonResult))
        {
            throw new Exception("error");
        }
        var resultObj = TopUtils.parseResultJson<TaobaoTbkTpwdCreateResponse>(jsonResult);
        if(string.IsNullOrEmpty(resultObj.Body))
        {
            resultObj.Body = jsonResult;
        }
        return resultObj;
    }

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