// Code generated by protoc-gen-go-http. DO NOT EDIT.
// versions:
// - protoc-gen-go-http v2.7.3
// - protoc             v3.19.4
// source: blog/v1/blog.proto

package v1

import (
	context "context"
	http "github.com/go-kratos/kratos/v2/transport/http"
	binding "github.com/go-kratos/kratos/v2/transport/http/binding"
)

// This is a compile-time assertion to ensure that this generated file
// is compatible with the kratos package it is being compiled against.
var _ = new(context.Context)
var _ = binding.EncodeURL

const _ = http.SupportPackageIsVersion1

const OperationBlogCreateBlog = "/api.blog.v1.Blog/CreateBlog"
const OperationBlogDeleteBlog = "/api.blog.v1.Blog/DeleteBlog"
const OperationBlogGetBlog = "/api.blog.v1.Blog/GetBlog"
const OperationBlogListBlogs = "/api.blog.v1.Blog/ListBlogs"
const OperationBlogUpdateBlog = "/api.blog.v1.Blog/UpdateBlog"

type BlogHTTPServer interface {
	CreateBlog(context.Context, *CreateBlogRequest) (*CreateBlogReply, error)
	DeleteBlog(context.Context, *DeleteBlogRequest) (*DeleteBlogReply, error)
	GetBlog(context.Context, *GetBlogRequest) (*GetBlogReply, error)
	ListBlogs(context.Context, *ListBlogsRequest) (*ListBlogsReply, error)
	UpdateBlog(context.Context, *UpdateBlogRequest) (*UpdateBlogReply, error)
}

func RegisterBlogHTTPServer(s *http.Server, srv BlogHTTPServer) {
	r := s.Route("/")
	r.GET("/v1/blogs", _Blog_ListBlogs0_HTTP_Handler(srv))
	r.GET("/v1/blogs/{id}", _Blog_GetBlog0_HTTP_Handler(srv))
	r.POST("/v1/blogs", _Blog_CreateBlog0_HTTP_Handler(srv))
	r.PUT("/v1/blogs/{id}", _Blog_UpdateBlog0_HTTP_Handler(srv))
	r.DELETE("/v1/blogs/{id}", _Blog_DeleteBlog0_HTTP_Handler(srv))
}

func _Blog_ListBlogs0_HTTP_Handler(srv BlogHTTPServer) func(ctx http.Context) error {
	return func(ctx http.Context) error {
		var in ListBlogsRequest
		if err := ctx.BindQuery(&in); err != nil {
			return err
		}
		http.SetOperation(ctx, OperationBlogListBlogs)
		h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) {
			return srv.ListBlogs(ctx, req.(*ListBlogsRequest))
		})
		out, err := h(ctx, &in)
		if err != nil {
			return err
		}
		reply := out.(*ListBlogsReply)
		return ctx.Result(200, reply)
	}
}

func _Blog_GetBlog0_HTTP_Handler(srv BlogHTTPServer) func(ctx http.Context) error {
	return func(ctx http.Context) error {
		var in GetBlogRequest
		if err := ctx.BindQuery(&in); err != nil {
			return err
		}
		if err := ctx.BindVars(&in); err != nil {
			return err
		}
		http.SetOperation(ctx, OperationBlogGetBlog)
		h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) {
			return srv.GetBlog(ctx, req.(*GetBlogRequest))
		})
		out, err := h(ctx, &in)
		if err != nil {
			return err
		}
		reply := out.(*GetBlogReply)
		return ctx.Result(200, reply)
	}
}

func _Blog_CreateBlog0_HTTP_Handler(srv BlogHTTPServer) func(ctx http.Context) error {
	return func(ctx http.Context) error {
		var in CreateBlogRequest
		if err := ctx.Bind(&in.Blog); err != nil {
			return err
		}
		if err := ctx.BindQuery(&in); err != nil {
			return err
		}
		http.SetOperation(ctx, OperationBlogCreateBlog)
		h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) {
			return srv.CreateBlog(ctx, req.(*CreateBlogRequest))
		})
		out, err := h(ctx, &in)
		if err != nil {
			return err
		}
		reply := out.(*CreateBlogReply)
		return ctx.Result(200, reply)
	}
}

func _Blog_UpdateBlog0_HTTP_Handler(srv BlogHTTPServer) func(ctx http.Context) error {
	return func(ctx http.Context) error {
		var in UpdateBlogRequest
		if err := ctx.Bind(&in.Blog); err != nil {
			return err
		}
		if err := ctx.BindQuery(&in); err != nil {
			return err
		}
		if err := ctx.BindVars(&in); err != nil {
			return err
		}
		http.SetOperation(ctx, OperationBlogUpdateBlog)
		h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) {
			return srv.UpdateBlog(ctx, req.(*UpdateBlogRequest))
		})
		out, err := h(ctx, &in)
		if err != nil {
			return err
		}
		reply := out.(*UpdateBlogReply)
		return ctx.Result(200, reply)
	}
}

func _Blog_DeleteBlog0_HTTP_Handler(srv BlogHTTPServer) func(ctx http.Context) error {
	return func(ctx http.Context) error {
		var in DeleteBlogRequest
		if err := ctx.BindQuery(&in); err != nil {
			return err
		}
		if err := ctx.BindVars(&in); err != nil {
			return err
		}
		http.SetOperation(ctx, OperationBlogDeleteBlog)
		h := ctx.Middleware(func(ctx context.Context, req interface{}) (interface{}, error) {
			return srv.DeleteBlog(ctx, req.(*DeleteBlogRequest))
		})
		out, err := h(ctx, &in)
		if err != nil {
			return err
		}
		reply := out.(*DeleteBlogReply)
		return ctx.Result(200, reply)
	}
}

type BlogHTTPClient interface {
	CreateBlog(ctx context.Context, req *CreateBlogRequest, opts ...http.CallOption) (rsp *CreateBlogReply, err error)
	DeleteBlog(ctx context.Context, req *DeleteBlogRequest, opts ...http.CallOption) (rsp *DeleteBlogReply, err error)
	GetBlog(ctx context.Context, req *GetBlogRequest, opts ...http.CallOption) (rsp *GetBlogReply, err error)
	ListBlogs(ctx context.Context, req *ListBlogsRequest, opts ...http.CallOption) (rsp *ListBlogsReply, err error)
	UpdateBlog(ctx context.Context, req *UpdateBlogRequest, opts ...http.CallOption) (rsp *UpdateBlogReply, err error)
}

type BlogHTTPClientImpl struct {
	cc *http.Client
}

func NewBlogHTTPClient(client *http.Client) BlogHTTPClient {
	return &BlogHTTPClientImpl{client}
}

func (c *BlogHTTPClientImpl) CreateBlog(ctx context.Context, in *CreateBlogRequest, opts ...http.CallOption) (*CreateBlogReply, error) {
	var out CreateBlogReply
	pattern := "/v1/blogs"
	path := binding.EncodeURL(pattern, in, false)
	opts = append(opts, http.Operation(OperationBlogCreateBlog))
	opts = append(opts, http.PathTemplate(pattern))
	err := c.cc.Invoke(ctx, "POST", path, in.Blog, &out, opts...)
	if err != nil {
		return nil, err
	}
	return &out, nil
}

func (c *BlogHTTPClientImpl) DeleteBlog(ctx context.Context, in *DeleteBlogRequest, opts ...http.CallOption) (*DeleteBlogReply, error) {
	var out DeleteBlogReply
	pattern := "/v1/blogs/{id}"
	path := binding.EncodeURL(pattern, in, true)
	opts = append(opts, http.Operation(OperationBlogDeleteBlog))
	opts = append(opts, http.PathTemplate(pattern))
	err := c.cc.Invoke(ctx, "DELETE", path, nil, &out, opts...)
	if err != nil {
		return nil, err
	}
	return &out, nil
}

func (c *BlogHTTPClientImpl) GetBlog(ctx context.Context, in *GetBlogRequest, opts ...http.CallOption) (*GetBlogReply, error) {
	var out GetBlogReply
	pattern := "/v1/blogs/{id}"
	path := binding.EncodeURL(pattern, in, true)
	opts = append(opts, http.Operation(OperationBlogGetBlog))
	opts = append(opts, http.PathTemplate(pattern))
	err := c.cc.Invoke(ctx, "GET", path, nil, &out, opts...)
	if err != nil {
		return nil, err
	}
	return &out, nil
}

func (c *BlogHTTPClientImpl) ListBlogs(ctx context.Context, in *ListBlogsRequest, opts ...http.CallOption) (*ListBlogsReply, error) {
	var out ListBlogsReply
	pattern := "/v1/blogs"
	path := binding.EncodeURL(pattern, in, true)
	opts = append(opts, http.Operation(OperationBlogListBlogs))
	opts = append(opts, http.PathTemplate(pattern))
	err := c.cc.Invoke(ctx, "GET", path, nil, &out, opts...)
	if err != nil {
		return nil, err
	}
	return &out, nil
}

func (c *BlogHTTPClientImpl) UpdateBlog(ctx context.Context, in *UpdateBlogRequest, opts ...http.CallOption) (*UpdateBlogReply, error) {
	var out UpdateBlogReply
	pattern := "/v1/blogs/{id}"
	path := binding.EncodeURL(pattern, in, false)
	opts = append(opts, http.Operation(OperationBlogUpdateBlog))
	opts = append(opts, http.PathTemplate(pattern))
	err := c.cc.Invoke(ctx, "PUT", path, in.Blog, &out, opts...)
	if err != nil {
		return nil, err
	}
	return &out, nil
}
