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

namespace Topsdk.Top.Ability3152;


public class Ability3152
{

    private ITopApiClient topApiClient;

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

    /*
        淘宝联盟厂商找优惠
        taobao.tbk.thor.mfrs.promotion.query
    */
    public TaobaoTbkThorMfrsPromotionQueryResponse TaobaoTbkThorMfrsPromotionQuery(TaobaoTbkThorMfrsPromotionQueryRequest request)
    {
        var jsonResult = topApiClient.Execute(request.GetApiCode(),request.ToRequestParam(),request.ToFileParam());
        if (string.IsNullOrEmpty(jsonResult))
        {
            throw new Exception("error");
        }
        var resultObj = TopUtils.parseResultJson<TaobaoTbkThorMfrsPromotionQueryResponse>(jsonResult);
        if(string.IsNullOrEmpty(resultObj.Body))
        {
            resultObj.Body = jsonResult;
        }
        return resultObj;
    }

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