package autocode

import (
	"github.com/flipped-aurora/gin-vue-admin/server/global"
    "github.com/flipped-aurora/gin-vue-admin/server/model/autocode"
    "github.com/flipped-aurora/gin-vue-admin/server/model/common/request"
    autocodeReq "github.com/flipped-aurora/gin-vue-admin/server/model/autocode/request"
    "github.com/flipped-aurora/gin-vue-admin/server/model/common/response"
    "github.com/flipped-aurora/gin-vue-admin/server/service"
    "github.com/gin-gonic/gin"
    "go.uber.org/zap"
)

type ProblemTypeApi struct {
}

var problemTypeService = service.ServiceGroupApp.AutoCodeServiceGroup.ProblemTypeService


// CreateProblemType 创建ProblemType
// @Tags ProblemType
// @Summary 创建ProblemType
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body autocode.ProblemType true "创建ProblemType"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /problemType/createProblemType [post]
func (problemTypeApi *ProblemTypeApi) CreateProblemType(c *gin.Context) {
	var problemType autocode.ProblemType
	_ = c.ShouldBindJSON(&problemType)
	if err := problemTypeService.CreateProblemType(problemType); err != nil {
        global.GVA_LOG.Error("创建失败!", zap.Any("err", err))
		response.FailWithMessage("创建失败", c)
	} else {
		response.OkWithMessage("创建成功", c)
	}
}

// DeleteProblemType 删除ProblemType
// @Tags ProblemType
// @Summary 删除ProblemType
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body autocode.ProblemType true "删除ProblemType"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"删除成功"}"
// @Router /problemType/deleteProblemType [delete]
func (problemTypeApi *ProblemTypeApi) DeleteProblemType(c *gin.Context) {
	var problemType autocode.ProblemType
	_ = c.ShouldBindJSON(&problemType)
	if err := problemTypeService.DeleteProblemType(problemType); err != nil {
        global.GVA_LOG.Error("删除失败!", zap.Any("err", err))
		response.FailWithMessage("删除失败", c)
	} else {
		response.OkWithMessage("删除成功", c)
	}
}

// DeleteProblemTypeByIds 批量删除ProblemType
// @Tags ProblemType
// @Summary 批量删除ProblemType
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.IdsReq true "批量删除ProblemType"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"批量删除成功"}"
// @Router /problemType/deleteProblemTypeByIds [delete]
func (problemTypeApi *ProblemTypeApi) DeleteProblemTypeByIds(c *gin.Context) {
	var IDS request.IdsReq
    _ = c.ShouldBindJSON(&IDS)
	if err := problemTypeService.DeleteProblemTypeByIds(IDS); err != nil {
        global.GVA_LOG.Error("批量删除失败!", zap.Any("err", err))
		response.FailWithMessage("批量删除失败", c)
	} else {
		response.OkWithMessage("批量删除成功", c)
	}
}

// UpdateProblemType 更新ProblemType
// @Tags ProblemType
// @Summary 更新ProblemType
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body autocode.ProblemType true "更新ProblemType"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"更新成功"}"
// @Router /problemType/updateProblemType [put]
func (problemTypeApi *ProblemTypeApi) UpdateProblemType(c *gin.Context) {
	var problemType autocode.ProblemType
	_ = c.ShouldBindJSON(&problemType)
	if err := problemTypeService.UpdateProblemType(problemType); err != nil {
        global.GVA_LOG.Error("更新失败!", zap.Any("err", err))
		response.FailWithMessage("更新失败", c)
	} else {
		response.OkWithMessage("更新成功", c)
	}
}

// FindProblemType 用id查询ProblemType
// @Tags ProblemType
// @Summary 用id查询ProblemType
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query autocode.ProblemType true "用id查询ProblemType"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /problemType/findProblemType [get]
func (problemTypeApi *ProblemTypeApi) FindProblemType(c *gin.Context) {
	var problemType autocode.ProblemType
	_ = c.ShouldBindQuery(&problemType)
	if err, reproblemType := problemTypeService.GetProblemType(problemType.ID); err != nil {
        global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
		response.FailWithMessage("查询失败", c)
	} else {
		response.OkWithData(gin.H{"reproblemType": reproblemType}, c)
	}
}

// GetProblemTypeList 分页获取ProblemType列表
// @Tags ProblemType
// @Summary 分页获取ProblemType列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query autocodeReq.ProblemTypeSearch true "分页获取ProblemType列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /problemType/getProblemTypeList [get]
func (problemTypeApi *ProblemTypeApi) GetProblemTypeList(c *gin.Context) {
	var pageInfo autocodeReq.ProblemTypeSearch
	_ = c.ShouldBindQuery(&pageInfo)
	if err, list, total := problemTypeService.GetProblemTypeInfoList(pageInfo); err != nil {
	    global.GVA_LOG.Error("获取失败!", zap.Any("err", err))
        response.FailWithMessage("获取失败", c)
    } else {
        response.OkWithDetailed(response.PageResult{
            List:     list,
            Total:    total,
            Page:     pageInfo.Page,
            PageSize: pageInfo.PageSize,
        }, "获取成功", c)
    }
}
