// Code generated by hertz generator.

package hertz

import (
	"context"

	"github.com/cloudwego/hertz/pkg/common/config"
	"github.com/cloudwego/hertz/pkg/protocol"
	hzClient "hertz-examples/hz/hz_client/client/hertz_gen/toutiao/middleware/hzClient"
)

type Client interface {
	FormMethod(context context.Context, req *hzClient.FormReq, reqOpt ...config.RequestOption) (resp *hzClient.Resp, rawResponse *protocol.Response, err error)
	QueryMethod(context context.Context, req *hzClient.QueryReq, reqOpt ...config.RequestOption) (resp *hzClient.Resp, rawResponse *protocol.Response, err error)
	PathMethod(context context.Context, req *hzClient.PathReq, reqOpt ...config.RequestOption) (resp *hzClient.Resp, rawResponse *protocol.Response, err error)
	BodyMethod(context context.Context, req *hzClient.BodyReq, reqOpt ...config.RequestOption) (resp *hzClient.Resp, rawResponse *protocol.Response, err error)
}

type HertzClient struct {
	client *cli
}

func NewHertzClient(hostUrl string, ops ...Option) (Client, error) {
	opts := getOptions(append(ops, withHostUrl(hostUrl))...)
	cli, err := newClient(opts)
	if err != nil {
		return nil, err
	}
	return &HertzClient{
		client: cli,
	}, nil
}

func (s *HertzClient) FormMethod(context context.Context, req *hzClient.FormReq, reqOpt ...config.RequestOption) (resp *hzClient.Resp, rawResponse *protocol.Response, err error) {
	httpResp := &hzClient.Resp{}
	ret, err := s.client.r().
		setContext(context).
		setQueryParams(map[string]interface{}{}).
		setPathParams(map[string]string{}).
		setHeaders(map[string]string{}).
		setFormParams(map[string]string{
			"form1": req.FormValue,
		}).
		setFormFileParams(map[string]string{
			"file1": req.FileValue,
		}).
		setRequestOption(reqOpt...).
		setResult(httpResp).
		execute("POST", "/form")
	if err != nil {
		return nil, nil, err
	}

	resp = httpResp
	rawResponse = ret.rawResponse
	return resp, rawResponse, nil
}

func (s *HertzClient) QueryMethod(context context.Context, req *hzClient.QueryReq, reqOpt ...config.RequestOption) (resp *hzClient.Resp, rawResponse *protocol.Response, err error) {
	httpResp := &hzClient.Resp{}
	ret, err := s.client.r().
		setContext(context).
		setQueryParams(map[string]interface{}{
			"query1": req.QueryValue,
		}).
		setPathParams(map[string]string{}).
		setHeaders(map[string]string{}).
		setFormParams(map[string]string{}).
		setFormFileParams(map[string]string{}).
		setBodyParam(req).
		setRequestOption(reqOpt...).
		setResult(httpResp).
		execute("GET", "/query")
	if err != nil {
		return nil, nil, err
	}

	resp = httpResp
	rawResponse = ret.rawResponse
	return resp, rawResponse, nil
}

func (s *HertzClient) PathMethod(context context.Context, req *hzClient.PathReq, reqOpt ...config.RequestOption) (resp *hzClient.Resp, rawResponse *protocol.Response, err error) {
	httpResp := &hzClient.Resp{}
	ret, err := s.client.r().
		setContext(context).
		setQueryParams(map[string]interface{}{}).
		setPathParams(map[string]string{
			"path1": req.PathValue,
		}).
		setHeaders(map[string]string{}).
		setFormParams(map[string]string{}).
		setFormFileParams(map[string]string{}).
		setBodyParam(req).
		setRequestOption(reqOpt...).
		setResult(httpResp).
		execute("POST", "/path:path1")
	if err != nil {
		return nil, nil, err
	}

	resp = httpResp
	rawResponse = ret.rawResponse
	return resp, rawResponse, nil
}

func (s *HertzClient) BodyMethod(context context.Context, req *hzClient.BodyReq, reqOpt ...config.RequestOption) (resp *hzClient.Resp, rawResponse *protocol.Response, err error) {
	httpResp := &hzClient.Resp{}
	ret, err := s.client.r().
		setContext(context).
		setQueryParams(map[string]interface{}{
			"query2": req.QueryValue,
		}).
		setPathParams(map[string]string{}).
		setHeaders(map[string]string{}).
		setFormParams(map[string]string{}).
		setFormFileParams(map[string]string{}).
		setBodyParam(req).
		setRequestOption(reqOpt...).
		setResult(httpResp).
		execute("POST", "/body")
	if err != nil {
		return nil, nil, err
	}

	resp = httpResp
	rawResponse = ret.rawResponse
	return resp, rawResponse, nil
}

var defaultClient, _ = NewHertzClient("http://127.0.0.1:8888")

func FormMethod(context context.Context, req *hzClient.FormReq, reqOpt ...config.RequestOption) (resp *hzClient.Resp, rawResponse *protocol.Response, err error) {
	return defaultClient.FormMethod(context, req, reqOpt...)
}

func QueryMethod(context context.Context, req *hzClient.QueryReq, reqOpt ...config.RequestOption) (resp *hzClient.Resp, rawResponse *protocol.Response, err error) {
	return defaultClient.QueryMethod(context, req, reqOpt...)
}

func PathMethod(context context.Context, req *hzClient.PathReq, reqOpt ...config.RequestOption) (resp *hzClient.Resp, rawResponse *protocol.Response, err error) {
	return defaultClient.PathMethod(context, req, reqOpt...)
}

func BodyMethod(context context.Context, req *hzClient.BodyReq, reqOpt ...config.RequestOption) (resp *hzClient.Resp, rawResponse *protocol.Response, err error) {
	return defaultClient.BodyMethod(context, req, reqOpt...)
}
