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

package base

import (
	"LAPP_ACURA_MOM_BACKEND/global"
	"LAPP_ACURA_MOM_BACKEND/grmi"
	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            : RegisterOneTightenWrenchRuleInfo
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个处理单条TightenWrenchRuleInfo的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : HTTP方法
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-11-23 11:13:02
 *
 ******************************************************************************/
func RegisterOneTightenWrenchRuleInfo(party router.Party, httpMethod string, path string, method func(*global.User, *model.TightenWrenchRuleInfo) 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.TightenWrenchRuleInfo)
		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            : RegisterIDOfTightenWrenchRuleInfo
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个通过主键处理单条TightenWrenchRuleInfo的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : HTTP方法
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-11-23 11:13:02
 *
 ******************************************************************************/
func RegisterIDOfTightenWrenchRuleInfo(party router.Party, httpMethod string, path string, method func(*global.User, int, int, int) 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
		operationId, err := ctx.Params().GetInt("operationId")
		if err != nil {
			supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil)
			return
		}
		workPlaceNr, err := ctx.Params().GetInt("workPlaceNr")
		if err != nil {
			supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil)
			return
		}
		ruleId, err := ctx.Params().GetInt("ruleId")
		if err != nil {
			supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil)
			return
		}

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

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

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

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

	RegisterIDOfTightenWrenchRuleInfo(party, "DELETE", path+"/{operationId:int}/{workPlaceNr:int}/{ruleId:int}", method)
}

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

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

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

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

/******************************************************************************
 *
 * @Function Name            : RegisterMultiTightenWrenchRuleInfo
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个处理多条TightenWrenchRuleInfo的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : HTTP方法
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-11-23 11:13:02
 *
 ******************************************************************************/
func RegisterMultiTightenWrenchRuleInfo(party router.Party, httpMethod string, path string, method func(*global.User, *[]model.TightenWrenchRuleInfo) 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.TightenWrenchRuleInfo, 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            : RegisterInsertTightenWrenchRuleInfo
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个插入多条TightenWrenchRuleInfo的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-11-23 11:13:02
 *
 ******************************************************************************/
func RegisterInsertTightenWrenchRuleInfo(party router.Party, path string, method func(*global.User, *[]model.TightenWrenchRuleInfo) error) {

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

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

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

/******************************************************************************
 *
 * @Function Name            : RegisterSelectTightenWrenchRuleInfo
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个查询TightenWrenchRuleInfo的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-11-23 11:13:02
 *
 ******************************************************************************/
func RegisterSelectTightenWrenchRuleInfo(party router.Party, path string, method func(*global.User, map[string]string) ([]model.TightenWrenchRuleInfo, 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            : RegisterQueryTightenWrenchRuleInfo
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个查询TightenWrenchRuleInfo并分页的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-11-23 11:13:02
 *
 ******************************************************************************/
func RegisterQueryTightenWrenchRuleInfo(party router.Party, path string, method func(*global.User, map[string]string) (grmi.PagingResult, 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            : RegisterUpdateTightenWrenchRuleInfo
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个修改多条TightenWrenchRuleInfo的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-11-23 11:13:02
 *
 ******************************************************************************/
func RegisterUpdateTightenWrenchRuleInfo(party router.Party, path string, method func(*global.User, *[]model.TightenWrenchRuleInfo) error) {

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