package controllers

import (
	"encoding/json"
	"oppmg/common/log"
	"oppmg/models"
	"oppmg/protocol"
	serveaudit "oppmg/services/audit"
	servecommon "oppmg/services/common"
)

type AuditController struct {
	BaseController
}

//AuditList 机会管理列表
//@router /v1/audit/list [post]
func (c *AuditController) AuditList() {
	var msg *protocol.ResponseMessage
	defer func() {
		c.ResposeJson(msg)
	}()
	var param protocol.RequestAuditList
	if err := json.Unmarshal(c.Ctx.Input.RequestBody, &param); err != nil {
		log.Error("json 解析失败", err)
		msg = protocol.BadRequestParam("1")
		return
	}
	uid := c.GetUserId()
	companyId := c.GetCompanyId()
	list, err := serveaudit.GetAuditList(param, companyId, uid)
	msg = protocol.NewReturnResponse(list, err)
	return
}

//AuditListBefore
//@router /v1/audit/list/before
func (c *AuditController) AuditListBefore() {
	var msg *protocol.ResponseMessage
	defer func() {
		c.ResposeJson(msg)
	}()
	// uid := c.GetUserId()
	companyId := c.GetCompanyId()
	templatelist := servecommon.SelectGetTemplateList(companyId)
	chanceTypeList := servecommon.SeleteGetChanceTypeList(companyId)
	departmentList := servecommon.SelectorDepartment(companyId, -1)
	publicStatus := models.ChancePublishStatusMap
	enableStatus := models.ChanceEnableStatusMap
	reviewStatus := models.ChanceReviewStatusMap
	data := map[string]interface{}{
		"template":      templatelist,
		"chance_type":   chanceTypeList,
		"public_status": publicStatus,
		"enable_status": enableStatus,
		"review_status": reviewStatus,
		"department":    departmentList,
	}
	msg = protocol.NewReturnResponse(data, nil)
	return
}