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

package qm

import (
	"LAPP_ACURA_MOM_BACKEND/global"
	model "LAPP_ACURA_MOM_BACKEND/models/qm"
	"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            : RegisterOneDefectReason
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个处理单条DefectReason的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : HTTP方法
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-03-18 22:49:12
 *
 ******************************************************************************/
func RegisterOneDefectReason(party router.Party, httpMethod string, path string, method func(*global.User, *model.DefectReason) error) {

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

		var err error = nil

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

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

		var err error = nil
		defectReasonId := ctx.Params().GetString("defectReasonId")

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

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

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

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

	RegisterIDOfDefectReason(party, "DELETE", path+"/{defectReasonId:string}", method)
}

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

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

		defectReasonId := ctx.Params().GetString("defectReasonId")
		result, err := method(user, defectReasonId)
		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            : RegisterUpdateOneDefectReason
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个修改单条DefectReason的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-03-18 22:49:12
 *
 ******************************************************************************/
func RegisterUpdateOneDefectReason(party router.Party, path string, method func(*global.User, *model.DefectReason) error) {

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

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

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

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

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

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

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

/******************************************************************************
 *
 * @Function Name            : RegisterSelectDefectReason
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个查询DefectReason的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-03-18 22:49:12
 *
 ******************************************************************************/
func RegisterSelectDefectReason(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            : RegisterUpdateDefectReason
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个修改多条DefectReason的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-03-18 22:49:12
 *
 ******************************************************************************/
func RegisterUpdateDefectReason(party router.Party, path string, method func(*global.User, *[]model.DefectReason) error) {

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