package workflow

import (
	"github.com/gin-gonic/gin"
	"server/dao"
	"server/global"
	"server/model/common/request"
	"server/model/common/response"
)

type ProjectProcessApi struct{}

func (ppa *ProjectProcessApi) QueryProjectApplicantList(c *gin.Context) {
	var info request.SearchProjectProcess
	err := c.ShouldBindJSON(&info)
	if err != nil {
		response.FailWithMessage("参数解析失败", c)
		global.GVA_LOG.Error("QueryProjectApplicantList ====== " + err.Error())
		return
	}
	list, total, err := projectProcessService.QueryProjectApplicantList(info)
	if err != nil {
		response.FailWithMessage("查询失败", c)
		global.GVA_LOG.Error("QueryProjectApplicantList ====== " + err.Error())
		return
	}
	response.OkWithDetailed(response.PageResult{
		List:     list,
		Total:    total,
		Page:     info.PageInfo.Page,
		PageSize: info.PageInfo.PageSize,
	}, "获取成功", c)
}

func (ppa *ProjectProcessApi) QueryProjectProcessList(c *gin.Context) {
	var info request.SearchProjectProcess
	err := c.ShouldBindJSON(&info)
	if err != nil {
		response.FailWithMessage("参数解析失败", c)
		global.GVA_LOG.Error("QueryProjectProgressList ====== " + err.Error())
		return
	}
	list, total, err := projectProcessService.QueryProjectProcessList(info)
	if err != nil {
		response.FailWithMessage("查询失败", c)
		global.GVA_LOG.Error("QueryProjectProgressList ====== " + err.Error())
		return
	}
	response.OkWithDetailed(response.PageResult{
		List:     list,
		Total:    total,
		Page:     info.PageInfo.Page,
		PageSize: info.PageInfo.PageSize,
	}, "获取成功", c)
}

func (ppa *ProjectProcessApi) CreateProjectProcess(c *gin.Context) {
	var pp dao.ProjectProcess
	err := c.ShouldBindJSON(&pp)
	if err != nil {
		response.FailWithMessage("参数解析失败", c)
		global.GVA_LOG.Error("CreateProjectProgress ====== " + err.Error())
		return
	}
	err = projectProcessService.CreateProjectProcess(pp)
	if err != nil {
		response.FailWithMessage("创建失败", c)
		global.GVA_LOG.Error("CreateProjectProgress ====== " + err.Error())
		return
	}
	response.OkWithMessage("创建成功", c)
}

func (ppa *ProjectProcessApi) UpdateProjectProcess(c *gin.Context) {
	var pp dao.ProjectProcess
	err := c.ShouldBindJSON(&pp)
	if err != nil {
		response.FailWithMessage("参数解析失败", c)
		global.GVA_LOG.Error("UpdateProjectProgress ====== " + err.Error())
		return
	}
	err = projectProcessService.UpdateProjectProcess(pp)
	if err != nil {
		response.FailWithMessage("更新失败", c)
		global.GVA_LOG.Error("UpdateProjectProgress ====== " + err.Error())
		return
	}
	response.OkWithMessage("更新成功", c)
}

func (ppa *ProjectProcessApi) DeleteProjectProcess(c *gin.Context) {
	var pp dao.ProjectProcess
	err := c.ShouldBindJSON(&pp)
	if err != nil {
		response.FailWithMessage("参数解析失败", c)
		global.GVA_LOG.Error("DeleteProjectProgress ====== " + err.Error())
		return
	}
	err = projectProcessService.DeleteProjectProcess(pp)
	if err != nil {
		response.FailWithMessage("删除失败", c)
		global.GVA_LOG.Error("DeleteProjectProgress ====== " + err.Error())
		return
	}
	response.OkWithMessage("删除成功", c)
}
