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

namespace Topsdk.Top.Ability865;


public class Ability865
{

    private ITopApiClient topApiClient;

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

    /*
        open account token验证
        taobao.open.account.token.validate
    */
    public TaobaoOpenAccountTokenValidateResponse TaobaoOpenAccountTokenValidate(TaobaoOpenAccountTokenValidateRequest request)
    {
        var jsonResult = topApiClient.Execute(request.GetApiCode(),request.ToRequestParam(),request.ToFileParam());
        if (string.IsNullOrEmpty(jsonResult))
        {
            throw new Exception("error");
        }
        var resultObj = TopUtils.parseResultJson<TaobaoOpenAccountTokenValidateResponse>(jsonResult);
        if(string.IsNullOrEmpty(resultObj.Body))
        {
            resultObj.Body = jsonResult;
        }
        return resultObj;
    }
    /*
        申请免登Open Account Token
        taobao.open.account.token.apply
    */
    public TaobaoOpenAccountTokenApplyResponse TaobaoOpenAccountTokenApply(TaobaoOpenAccountTokenApplyRequest request)
    {
        var jsonResult = topApiClient.Execute(request.GetApiCode(),request.ToRequestParam(),request.ToFileParam());
        if (string.IsNullOrEmpty(jsonResult))
        {
            throw new Exception("error");
        }
        var resultObj = TopUtils.parseResultJson<TaobaoOpenAccountTokenApplyResponse>(jsonResult);
        if(string.IsNullOrEmpty(resultObj.Body))
        {
            resultObj.Body = jsonResult;
        }
        return resultObj;
    }

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