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

namespace Topsdk.Top.Ability370;


public class Ability370
{

    private ITopApiClient topApiClient;

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

    /*
        淘宝客-推广者-店铺搜索
        taobao.tbk.shop.get
    */
    public TaobaoTbkShopGetResponse TaobaoTbkShopGet(TaobaoTbkShopGetRequest request)
    {
        var jsonResult = topApiClient.Execute(request.GetApiCode(),request.ToRequestParam(),request.ToFileParam());
        if (string.IsNullOrEmpty(jsonResult))
        {
            throw new Exception("error");
        }
        var resultObj = TopUtils.parseResultJson<TaobaoTbkShopGetResponse>(jsonResult);
        if(string.IsNullOrEmpty(resultObj.Body))
        {
            resultObj.Body = jsonResult;
        }
        return resultObj;
    }
    /*
        淘宝客-推广者-物料搜索（临时接口）
        taobao.tbk.dg.material.temporary.optional
    */
    public TaobaoTbkDgMaterialTemporaryOptionalResponse TaobaoTbkDgMaterialTemporaryOptional(TaobaoTbkDgMaterialTemporaryOptionalRequest request)
    {
        var jsonResult = topApiClient.Execute(request.GetApiCode(),request.ToRequestParam(),request.ToFileParam());
        if (string.IsNullOrEmpty(jsonResult))
        {
            throw new Exception("error");
        }
        var resultObj = TopUtils.parseResultJson<TaobaoTbkDgMaterialTemporaryOptionalResponse>(jsonResult);
        if(string.IsNullOrEmpty(resultObj.Body))
        {
            resultObj.Body = jsonResult;
        }
        return resultObj;
    }

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