// Code generated by go-mir. DO NOT EDIT.
// versions:
// - mir 5.3

package v1

import (
	"context"
	"net/http"

	"github.com/alimy/mir/v5"
	"github.com/gin-gonic/gin"
)

type _binding_ interface {
	Bind(*gin.Context) error
}

type _render_ interface {
	Render(*gin.Context)
}

type _default_ interface {
	Bind(*gin.Context, any) error
	Render(*gin.Context, any, error)
}

type Admin interface {
	_default_

	// Chain provide handlers chain for gin
	Chain() gin.HandlersChain

	Quit(context.Context) error
	Teams(context.Context) error
	DelUser(context.Context) error
	User(context.Context) error

	mustEmbedUnimplementedAdminServant()
}

type AdminChain interface {
	ChainTeams() gin.HandlersChain
	ChainDelUser() gin.HandlersChain
	ChainUser() gin.HandlersChain

	mustEmbedUnimplementedAdminChain()
}

// RegisterAdminServant register Admin servant to gin
func RegisterAdminServant(e *gin.Engine, s Admin, m ...AdminChain) {
	var cc AdminChain
	if len(m) > 0 {
		cc = m[0]
	} else {
		cc = &UnimplementedAdminChain{}
	}
	router := e.Group("v1")
	// use chain for router
	middlewares := s.Chain()
	router.Use(middlewares...)

	// register routes info to router
	router.Handle("POST", "user/quit", func(c *gin.Context) {
		select {
		case <-c.Request.Context().Done():
			return
		default:
		}

		s.Render(c, nil, s.Quit(c.Request.Context()))
	})
	{
		h := append(cc.ChainTeams(), func(c *gin.Context) {
			select {
			case <-c.Request.Context().Done():
				return
			default:
			}

			s.Render(c, nil, s.Teams(c.Request.Context()))
		})
		router.Handle("GET", "teams/:category", h...)
		router.Handle("HEAD", "teams/:category", h...)
		router.Handle("POST", "teams/:category", h...)
	}
	router.Handle("DELETE", "user", append(cc.ChainDelUser(), func(c *gin.Context) {
		select {
		case <-c.Request.Context().Done():
			return
		default:
		}

		s.Render(c, nil, s.DelUser(c.Request.Context()))
	})...)
	router.Handle("GET", "user", append(cc.ChainUser(), func(c *gin.Context) {
		select {
		case <-c.Request.Context().Done():
			return
		default:
		}

		s.Render(c, nil, s.User(c.Request.Context()))
	})...)
}

// UnimplementedAdminServant can be embedded to have forward compatible implementations.
type UnimplementedAdminServant struct{}

func (UnimplementedAdminServant) Chain() gin.HandlersChain {
	return nil
}

func (UnimplementedAdminServant) Quit(c context.Context) error {
	return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented))
}

func (UnimplementedAdminServant) Teams(c context.Context) error {
	return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented))
}

func (UnimplementedAdminServant) DelUser(c context.Context) error {
	return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented))
}

func (UnimplementedAdminServant) User(c context.Context) error {
	return mir.Errorln(http.StatusNotImplemented, http.StatusText(http.StatusNotImplemented))
}

func (UnimplementedAdminServant) mustEmbedUnimplementedAdminServant() {}

// UnimplementedAdminChain can be embedded to have forward compatible implementations.
type UnimplementedAdminChain struct{}

func (b *UnimplementedAdminChain) ChainTeams() gin.HandlersChain {
	return nil
}

func (b *UnimplementedAdminChain) ChainDelUser() gin.HandlersChain {
	return nil
}

func (b *UnimplementedAdminChain) ChainUser() gin.HandlersChain {
	return nil
}

func (b *UnimplementedAdminChain) mustEmbedUnimplementedAdminChain() {}
