// Copyright (c) Shenyang Leading Edge Intelligent Technology Co., Ltd. All rights reserved.

package base

import (
	model "LAPP_LF_MOM_BACKEND/models/base"
	"LAPP_LF_MOM_BACKEND/web/middleware/jwts"
	"LAPP_LF_MOM_BACKEND/web/models"
	"LAPP_LF_MOM_BACKEND/web/supports"
	"github.com/kataras/iris/v12"
	"github.com/kataras/iris/v12/core/router"
)

/******************************************************************************
 *
 * @Function Name            : RegisterOneWorkShiftEffLst
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个处理单条WorkShiftEffLst的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : HTTP方法
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-03-18 22:49:12
 *
 ******************************************************************************/
func RegisterOneWorkShiftEffLst(party router.Party, httpMethod string, path string, method func(*models.Usertab, *model.WorkShiftEffLst) error) {

	party.Handle(httpMethod, path, func(ctx iris.Context) {
		user, ok := jwts.ParseToken(ctx)
		if !ok {
			supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil)
			return
		}

		var err error = nil

		entity := new(model.WorkShiftEffLst)
		if ctx.GetContentLength() > 0 {
			err := ctx.ReadJSON(entity)
			if err != nil {
				supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil)
				return
			}
		} else {
			entity = nil
		}

		err = method(user, entity)
		if err != nil {
			supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil)
			return
		}
		supports.Ok(ctx, supports.OptionSuccess, nil)
	})
}

/******************************************************************************
 *
 * @Function Name            : RegisterIDOfWorkShiftEffLst
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个通过主键处理单条WorkShiftEffLst的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : HTTP方法
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-03-18 22:49:12
 *
 ******************************************************************************/
func RegisterIDOfWorkShiftEffLst(party router.Party, httpMethod string, path string, method func(*models.Usertab, int, string) error) {

	party.Handle(httpMethod, path, func(ctx iris.Context) {
		user, ok := jwts.ParseToken(ctx)
		if !ok {
			supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil)
			return
		}

		var err error = nil
		workShiftNr, err := ctx.Params().GetInt("workShiftNr")
		if err != nil {
			supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil)
			return
		}
		levelId := ctx.Params().GetString("levelId")

		err = method(user, workShiftNr, levelId)
		if err != nil {
			supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil)
			return
		}
		supports.Ok(ctx, supports.OptionSuccess, nil)
	})
}

/******************************************************************************
 *
 * @Function Name            : RegisterInsertOneWorkShiftEffLst
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个插入单条WorkShiftEffLst的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-03-18 22:49:12
 *
 ******************************************************************************/
func RegisterInsertOneWorkShiftEffLst(party router.Party, path string, method func(*models.Usertab, *model.WorkShiftEffLst) error) {

	RegisterOneWorkShiftEffLst(party, "POST", path, method)
}

/******************************************************************************
 *
 * @Function Name            : RegisterDeleteOneWorkShiftEffLst
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个删除单条WorkShiftEffLst的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-03-18 22:49:12
 *
 ******************************************************************************/
func RegisterDeleteOneWorkShiftEffLst(party router.Party, path string, method func(*models.Usertab, int, string) error) {

	RegisterIDOfWorkShiftEffLst(party, "DELETE", path+"/{workShiftNr:int}/{levelId:string}", method)
}

/******************************************************************************
 *
 * @Function Name            : RegisterSelectOneWorkShiftEffLst
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个查找单条WorkShiftEffLst的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-03-18 22:49:12
 *
 ******************************************************************************/
func RegisterSelectOneWorkShiftEffLst(party router.Party, path string, method func(*models.Usertab, int, string) (*model.WorkShiftEffLst, error)) {

	party.Get(path+"/{workShiftNr:int}/{levelId:string}", func(ctx iris.Context) {
		user, ok := jwts.ParseToken(ctx)
		if !ok {
			supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil)
			return
		}

		workShiftNr, err := ctx.Params().GetInt("workShiftNr")
		if err != nil {
			supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil)
			return
		}
		levelId := ctx.Params().GetString("levelId")
		result, err := method(user, workShiftNr, levelId)
		if err != nil {
			supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil)
			return
		}
		if result == nil {
			supports.Error(ctx, iris.StatusNotFound, supports.NotFound, nil)
			return
		}
		supports.Ok(ctx, supports.OptionSuccess, result)
	})
}

/******************************************************************************
 *
 * @Function Name            : RegisterUpdateOneWorkShiftEffLst
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个修改单条WorkShiftEffLst的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-03-18 22:49:12
 *
 ******************************************************************************/
func RegisterUpdateOneWorkShiftEffLst(party router.Party, path string, method func(*models.Usertab, *model.WorkShiftEffLst) error) {

	RegisterOneWorkShiftEffLst(party, "PUT", path, method)
}

/******************************************************************************
 *
 * @Function Name            : RegisterMultiWorkShiftEffLst
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个处理多条WorkShiftEffLst的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : HTTP方法
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-03-18 22:49:12
 *
 ******************************************************************************/
func RegisterMultiWorkShiftEffLst(party router.Party, httpMethod string, path string, method func(*models.Usertab, *[]model.WorkShiftEffLst) error) {

	party.Handle(httpMethod, path, func(ctx iris.Context) {
		user, ok := jwts.ParseToken(ctx)
		if !ok {
			supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil)
			return
		}

		entities := make([]model.WorkShiftEffLst, 0, 10)
		err := ctx.ReadJSON(&entities)
		if err != nil {
			supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil)
			return
		}

		err = method(user, &entities)
		if err != nil {
			supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil)
			return
		}
		supports.Ok(ctx, supports.OptionSuccess, nil)
	})
}

/******************************************************************************
 *
 * @Function Name            : RegisterInsertWorkShiftEffLst
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个插入多条WorkShiftEffLst的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-03-18 22:49:12
 *
 ******************************************************************************/
func RegisterInsertWorkShiftEffLst(party router.Party, path string, method func(*models.Usertab, *[]model.WorkShiftEffLst) error) {

	RegisterMultiWorkShiftEffLst(party, "POST", path, method)
}

/******************************************************************************
 *
 * @Function Name            : RegisterDeleteWorkShiftEffLst
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个删除多条WorkShiftEffLst的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-03-18 22:49:12
 *
 ******************************************************************************/
func RegisterDeleteWorkShiftEffLst(party router.Party, path string, method func(*models.Usertab, *[]model.WorkShiftEffLst) error) {

	RegisterMultiWorkShiftEffLst(party, "DELETE", path, method)
}

/******************************************************************************
 *
 * @Function Name            : RegisterSelectWorkShiftEffLst
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个查询WorkShiftEffLst的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-03-18 22:49:12
 *
 ******************************************************************************/
func RegisterSelectWorkShiftEffLst(party router.Party, path string, method func(*models.Usertab, map[string]string) (interface{}, error)) {

	party.Get(path, func(ctx iris.Context) {
		user, ok := jwts.ParseToken(ctx)
		if !ok {
			supports.Error(ctx, iris.StatusBadRequest, supports.ParseParamsFailur, nil)
			return
		}

		result, err := method(user, ctx.URLParams())
		if err != nil {
			supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil)
			return
		}
		supports.Ok(ctx, supports.OptionSuccess, result)
	})
}

/******************************************************************************
 *
 * @Function Name            : RegisterUpdateWorkShiftEffLst
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个修改多条WorkShiftEffLst的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-03-18 22:49:12
 *
 ******************************************************************************/
func RegisterUpdateWorkShiftEffLst(party router.Party, path string, method func(*models.Usertab, *[]model.WorkShiftEffLst) error) {

	RegisterMultiWorkShiftEffLst(party, "PUT", path, method)
}
