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

namespace Topsdk.Top.Ability425;


public class Ability425
{

    private ITopApiClient topApiClient;

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

    /*
        淘宝客-公用-私域用户邀请码生成
        taobao.tbk.sc.invitecode.get
    */
    public TaobaoTbkScInvitecodeGetResponse TaobaoTbkScInvitecodeGet(TaobaoTbkScInvitecodeGetRequest request,String session)
    {
        var jsonResult = topApiClient.Execute(request.GetApiCode(),request.ToRequestParam(),request.ToFileParam(),session);
        if (string.IsNullOrEmpty(jsonResult))
        {
            throw new Exception("error");
        }
        var resultObj = TopUtils.parseResultJson<TaobaoTbkScInvitecodeGetResponse>(jsonResult);
        if(string.IsNullOrEmpty(resultObj.Body))
        {
            resultObj.Body = jsonResult;
        }
        return resultObj;
    }
    /*
        淘宝客-公用-私域用户备案
        taobao.tbk.sc.publisher.info.save
    */
    public TaobaoTbkScPublisherInfoSaveResponse TaobaoTbkScPublisherInfoSave(TaobaoTbkScPublisherInfoSaveRequest request,String session)
    {
        var jsonResult = topApiClient.Execute(request.GetApiCode(),request.ToRequestParam(),request.ToFileParam(),session);
        if (string.IsNullOrEmpty(jsonResult))
        {
            throw new Exception("error");
        }
        var resultObj = TopUtils.parseResultJson<TaobaoTbkScPublisherInfoSaveResponse>(jsonResult);
        if(string.IsNullOrEmpty(resultObj.Body))
        {
            resultObj.Body = jsonResult;
        }
        return resultObj;
    }
    /*
        淘宝客-公用-私域用户备案信息查询
        taobao.tbk.sc.publisher.info.get
    */
    public TaobaoTbkScPublisherInfoGetResponse TaobaoTbkScPublisherInfoGet(TaobaoTbkScPublisherInfoGetRequest request,String session)
    {
        var jsonResult = topApiClient.Execute(request.GetApiCode(),request.ToRequestParam(),request.ToFileParam(),session);
        if (string.IsNullOrEmpty(jsonResult))
        {
            throw new Exception("error");
        }
        var resultObj = TopUtils.parseResultJson<TaobaoTbkScPublisherInfoGetResponse>(jsonResult);
        if(string.IsNullOrEmpty(resultObj.Body))
        {
            resultObj.Body = jsonResult;
        }
        return resultObj;
    }

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