// 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"
	"time"
)

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

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

		var err error = nil

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

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

		var err error = nil
		workLineId := ctx.Params().GetString("workLineId")
		workDay := ctx.Params().GetString("workDay")
		pos, err := ctx.Params().GetInt("pos")
		if err != nil {
			supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil)
			return
		}
		begTimeOrigin, err := time.Parse(grmi.URLDateTimeFormat, ctx.Params().GetString("begTime"))
		if err != nil {
			supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil)
		}
		begTime := grmi.DateTime(begTimeOrigin)

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

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

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

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

	RegisterIDOfWorkLineWorkShiftSpecialTime(party, "DELETE", path+"/{workLineId:string}/{workDay:string}/{pos:int}/{begTime:string}", method)
}

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

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

		workLineId := ctx.Params().GetString("workLineId")
		workDay := ctx.Params().GetString("workDay")
		pos, err := ctx.Params().GetInt("pos")
		if err != nil {
			supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil)
			return
		}
		begTimeOrigin, err := time.Parse(grmi.URLDateTimeFormat, ctx.Params().GetString("begTime"))
		if err != nil {
			supports.Error(ctx, iris.StatusBadRequest, err.Error(), nil)
		}
		begTime := grmi.DateTime(begTimeOrigin)
		result, err := method(user, workLineId, workDay, pos, begTime)
		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            : RegisterUpdateOneWorkLineWorkShiftSpecialTime
 *-----------------------------------------------------------------------------
 *
 * @Description              : 为一个修改单条WorkLineWorkShiftSpecialTime的方法注册路由
 *
 * @Function Parameters      : 路由分组
 *
 * @Function Parameters      : 路径
 *
 * @Function Parameters      : 实际处理请求的方法
 *
 * @Author                   : 代码生成器创建
 *
 * @Date                     : 2021-03-18 22:49:12
 *
 ******************************************************************************/
func RegisterUpdateOneWorkLineWorkShiftSpecialTime(party router.Party, path string, method func(*global.User, *model.WorkLineWorkShiftSpecialTime) error) {

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

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

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

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

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

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

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

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

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