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

package base

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

/******************************************************************************
 *
 * @Function Name            : RegisterOneWorkPlaceStatusRecLst
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个处理单条WorkPlaceStatusRecLst的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : HTTP方法
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-04-21 10:27:00
 *
 ******************************************************************************/
func RegisterOneWorkPlaceStatusRecLst(party router.Party, httpMethod string, path string, method func(*global.User, *model.WorkPlaceStatusRecLst) error) {

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

		var err error = nil

		entity := new(model.WorkPlaceStatusRecLst)
		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            : RegisterIDOfWorkPlaceStatusRecLst
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个通过主键处理单条WorkPlaceStatusRecLst的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : HTTP方法
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-04-21 10:27:00
 *
 ******************************************************************************/
func RegisterIDOfWorkPlaceStatusRecLst(party router.Party, httpMethod string, path string, method func(*global.User, int, int) error) {

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

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

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

/******************************************************************************
 *
 * @Function Name            : RegisterInsertOneWorkPlaceStatusRecLst
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个插入单条WorkPlaceStatusRecLst的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-04-21 10:27:00
 *
 ******************************************************************************/
func RegisterInsertOneWorkPlaceStatusRecLst(party router.Party, path string, method func(*global.User, *model.WorkPlaceStatusRecLst) error) {

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

/******************************************************************************
 *
 * @Function Name            : RegisterDeleteOneWorkPlaceStatusRecLst
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个删除单条WorkPlaceStatusRecLst的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-04-21 10:27:00
 *
 ******************************************************************************/
func RegisterDeleteOneWorkPlaceStatusRecLst(party router.Party, path string, method func(*global.User, int, int) error) {

	RegisterIDOfWorkPlaceStatusRecLst(party, "DELETE", path+"/{workPlaceNr:int}/{pos:int}", method)
}

/******************************************************************************
 *
 * @Function Name            : RegisterSelectOneWorkPlaceStatusRecLst
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个查找单条WorkPlaceStatusRecLst的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-04-21 10:27:00
 *
 ******************************************************************************/
func RegisterSelectOneWorkPlaceStatusRecLst(party router.Party, path string, method func(*global.User, int, int) (*model.WorkPlaceStatusRecLst, error)) {

	party.Get(path+"/{workPlaceNr:int}/{pos:int}", func(ctx iris.Context) {
		user, ok := jwts.ParseToken(ctx)
		if !ok {
			return
		}

		workPlaceNr, err := ctx.Params().GetInt("workPlaceNr")
		if err != nil {
			supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil)
			return
		}
		pos, err := ctx.Params().GetInt("pos")
		if err != nil {
			supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil)
			return
		}
		result, err := method(user, workPlaceNr, pos)
		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            : RegisterUpdateOneWorkPlaceStatusRecLst
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个修改单条WorkPlaceStatusRecLst的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-04-21 10:27:00
 *
 ******************************************************************************/
func RegisterUpdateOneWorkPlaceStatusRecLst(party router.Party, path string, method func(*global.User, *model.WorkPlaceStatusRecLst) error) {

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

/******************************************************************************
 *
 * @Function Name            : RegisterMultiWorkPlaceStatusRecLst
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个处理多条WorkPlaceStatusRecLst的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : HTTP方法
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-04-21 10:27:00
 *
 ******************************************************************************/
func RegisterMultiWorkPlaceStatusRecLst(party router.Party, httpMethod string, path string, method func(*global.User, *[]model.WorkPlaceStatusRecLst) error) {

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

		entities := make([]model.WorkPlaceStatusRecLst, 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            : RegisterInsertWorkPlaceStatusRecLst
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个插入多条WorkPlaceStatusRecLst的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-04-21 10:27:00
 *
 ******************************************************************************/
func RegisterInsertWorkPlaceStatusRecLst(party router.Party, path string, method func(*global.User, *[]model.WorkPlaceStatusRecLst) error) {

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

/******************************************************************************
 *
 * @Function Name            : RegisterDeleteWorkPlaceStatusRecLst
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个删除多条WorkPlaceStatusRecLst的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-04-21 10:27:00
 *
 ******************************************************************************/
func RegisterDeleteWorkPlaceStatusRecLst(party router.Party, path string, method func(*global.User, *[]model.WorkPlaceStatusRecLst) error) {

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

/******************************************************************************
 *
 * @Function Name            : RegisterSelectWorkPlaceStatusRecLst
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个查询WorkPlaceStatusRecLst的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-04-21 10:27:00
 *
 ******************************************************************************/
func RegisterSelectWorkPlaceStatusRecLst(party router.Party, path string, method func(*global.User, map[string]string) (interface{}, error)) {

	party.Get(path, func(ctx iris.Context) {
		user, ok := jwts.ParseToken(ctx)
		if !ok {
			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            : RegisterUpdateWorkPlaceStatusRecLst
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个修改多条WorkPlaceStatusRecLst的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-04-21 10:27:00
 *
 ******************************************************************************/
func RegisterUpdateWorkPlaceStatusRecLst(party router.Party, path string, method func(*global.User, *[]model.WorkPlaceStatusRecLst) error) {

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