package report_approve

import (
	"encoding/json"
	"eta/eta_mobile/controllers"
	"eta/eta_mobile/models"
	"eta/eta_mobile/models/report_approve"
	"eta/eta_mobile/services"
)

// ReportApproveController 报告审批
type ReportApproveController struct {
	controllers.BaseAuthController
}

// CheckApproveOpen
// @Title 校验分类是否开启审批
// @Description 校验分类是否开启审批
// @Param	request	body report_approve.ReportApproveCheckApproveOpenReq true "type json string"
// @Success 200 string "操作成功"
// @router /classify/check_open [post]
func (this *ReportApproveController) CheckApproveOpen() {
	br := new(models.BaseResponse).Init()
	defer func() {
		if br.ErrMsg == "" {
			br.IsSendEmail = false
		}
		this.Data["json"] = br
		this.ServeJSON()
	}()
	sysUser := this.SysUser
	if sysUser == nil {
		br.Msg = "请登录"
		br.ErrMsg = "请登录，SysUser Is Empty"
		br.Ret = 408
		return
	}
	var req report_approve.ReportApproveCheckApproveOpenReq
	if e := json.Unmarshal(this.Ctx.Input.RequestBody, &req); e != nil {
		br.Msg = "参数有误"
		br.ErrMsg = "参数解析失败, Err: " + e.Error()
		return
	}

	// 校验是否开启了审批流
	opening, e := services.CheckReportOpenApprove(req.ReportType, req.ClassifyFirstId, req.ClassifySecondId, req.ClassifyThirdId)
	if e != nil {
		br.Msg = "操作失败"
		br.ErrMsg = "校验报告是否开启审批流失败, Err: " + e.Error()
		return
	}

	br.Data = opening
	br.Ret = 200
	br.Success = true
	br.Msg = "操作成功"
}
