
package cn.orionsec.ops.handler.http;

import cn.orionsec.kit.http.ok.OkResponse;
import cn.orionsec.kit.lang.define.wrapper.HttpWrapper;
import com.alibaba.fastjson.TypeReference;

public interface HttpApiRequester<API extends HttpApiDefined> {

    /**
     * 请求 api
     *
     * @return OkResponse
     */
    default OkResponse await() {
        return this.getRequest().await();
    }

    /**
     * 请求 api
     *
     * @param dataClass dataClass
     * @param <T>       T
     * @return HttpWrapper
     */
    default <T> HttpWrapper<T> request(Class<T> dataClass) {
        return this.getRequest().getHttpWrapper(dataClass);
    }

    /**
     * 请求 api
     *
     * @param type type
     * @param <T>  T
     * @return T
     */
    default <T> T request(TypeReference<T> type) {
        return this.getRequest().getJson(type);
    }

    /**
     * 请求 api
     *
     * @param requestBody requestBody
     * @param dataClass   dataClass
     * @param <T>         T
     * @return HttpWrapper
     */
    default <T> HttpWrapper<T> request(Object requestBody, Class<T> dataClass) {
        return this.getRequest().jsonBody(requestBody).getHttpWrapper(dataClass);
    }

    /**
     * 请求 api
     *
     * @param requestBody requestBody
     * @param type        type
     * @param <T>         T
     * @return T
     */
    default <T> T request(Object requestBody, TypeReference<T> type) {
        return this.getRequest().jsonBody(requestBody).getJson(type);
    }

    /**
     * 获取 api request
     *
     * @return request
     */
    HttpApiRequest getRequest();

}
