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

namespace Topsdk.Top.Ability373;


public class Ability373
{

    private ITopApiClient topApiClient;

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

    /*
        聚划算商品搜索接口
        taobao.ju.items.search
    */
    public TaobaoJuItemsSearchResponse TaobaoJuItemsSearch(TaobaoJuItemsSearchRequest request)
    {
        var jsonResult = topApiClient.Execute(request.GetApiCode(),request.ToRequestParam(),request.ToFileParam());
        if (string.IsNullOrEmpty(jsonResult))
        {
            throw new Exception("error");
        }
        var resultObj = TopUtils.parseResultJson<TaobaoJuItemsSearchResponse>(jsonResult);
        if(string.IsNullOrEmpty(resultObj.Body))
        {
            resultObj.Body = jsonResult;
        }
        return resultObj;
    }

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