package autocode

import (
	"github.com/flipped-aurora/gin-vue-admin/server/global"
	"github.com/flipped-aurora/gin-vue-admin/server/model/autocode"
	autocodeReq "github.com/flipped-aurora/gin-vue-admin/server/model/autocode/request"
	"github.com/flipped-aurora/gin-vue-admin/server/model/common/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 PlaceProApi struct {
}

var placeProService = service.ServiceGroupApp.AutoCodeServiceGroup.PlaceProService

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

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

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

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

// FindPlacePro 用id查询PlacePro
// @Tags PlacePro
// @Summary 用id查询PlacePro
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query autocode.PlacePro true "用id查询PlacePro"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"查询成功"}"
// @Router /placePro/findPlacePro [get]
func (placeProApi *PlaceProApi) FindPlacePro(c *gin.Context) {
	var placePro autocode.PlacePro
	_ = c.ShouldBindQuery(&placePro)
	if err, replacePro := placeProService.GetPlacePro(placePro.ID); err != nil {
		global.GVA_LOG.Error("查询失败!", zap.Any("err", err))
		response.FailWithMessage("查询失败", c)
	} else {
		response.OkWithData(gin.H{"replacePro": replacePro}, c)
	}
}

// GetPlaceProList 分页获取PlacePro列表
// @Tags PlacePro
// @Summary 分页获取PlacePro列表
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data query autocodeReq.PlaceProSearch true "分页获取PlacePro列表"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"获取成功"}"
// @Router /placePro/getPlaceProList [get]
func (placeProApi *PlaceProApi) GetPlaceProList(c *gin.Context) {
	var pageInfo autocodeReq.PlaceProSearch
	_ = c.ShouldBindQuery(&pageInfo)
	if err, list, total := placeProService.GetPlaceProInfoList(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)
	}
}
