/**
* @Author: zou.yingbin
* @Create  : 2021/1/26 13:41
* @Modify  : 2021/1/26 13:41
 */

package ermcp

import (
	"github.com/gin-gonic/gin"
	"mtp2_if/global/app"
	"mtp2_if/global/e"
	"mtp2_if/models"
	"net/http"
)

// 查询套保品种请求
type QryMiddleGoodsReq struct {
	UserId int64  `form:"userid" binding:"required"` //用户ID
	Status *int32 `form:"status" binding:"required"` //状态
}

// 查询套保品种应答
type QryMiddleGoodsRsp models.ErmcpMiddleGoodsModel

// @Summary 查询套保品种(菜单:套保品种)
// @Produce json
// @Security ApiKeyAuth
// @Param userid query int true  "所属机构ID"
// @Param status query int true  "状态 0-停用 1-正常"
// @Success 200 {array} QryMiddleGoodsRsp
// @Failure 500 {object} app.Response
// @Router /Ermcp/QueryMiddleGoods [get]
// @Tags 企业风险管理(app)
func QueryMiddleGoods(c *gin.Context) {
	appG := app.GinUtils{Gin: app.Gin{C: c}}
	var req QryMiddleGoodsReq
	appG.DoBindReq(&req)
	m := models.ErmcpMiddleGoodsModel{AREAUSERID: req.UserId, ISVALID: *req.Status}
	appG.DoGetData(&m)
}

// 查询套保品种详情请求
type QryMiddleGoodsDetailReq struct {
	UserId        int64  `form:"userid" binding:"required"` //用户ID
	MiddleGoodsId uint32 `form:"middlegoodsid"`             // 套保品种ID
}

// 查询套保品种详情应答
type QryMiddleGoodsDetailRsp models.ErmcpMiddleGoodsDetail

// @Summary 查询套保品种详情(菜单:套保品种/商品详情)
// @Produce json
// @Security ApiKeyAuth
// @Param userid query int true  "所属机构ID"
// @Param middlegoodsid query int false  "套保品种id"
// @Success 200 {array} QryMiddleGoodsDetailRsp
// @Failure 500 {object} app.Response
// @Router /Ermcp/QueryMiddleGoodsDetail [get]
// @Tags 企业风险管理(app)
func QueryMiddleGoodsDetail(c *gin.Context) {
	appG := app.Gin{C: c}
	var req QryMiddleGoodsDetailReq
	if err := c.ShouldBind(&req); err != nil {
		appG.Response(http.StatusBadRequest, e.INVALID_PARAMS, nil)
		return
	}
	m := models.ErmcpMiddleGoodsDetail{Mg: models.ErmcpMiddleGoodsModel{AREAUSERID: req.UserId, MIDDLEGOODSID: req.MiddleGoodsId}}
	if d, err := m.GetData(); err == nil {
		appG.Response(http.StatusOK, e.SUCCESS, d)
	} else {
		//appG.Response(http.StatusBadRequest, e.ERROR_QUERY_FAIL, nil)
		appG.Response(http.StatusOK, e.SUCCESS, nil)
	}
}

// 查询套保品种变更记录请求
type QryMGChangeLogReq struct {
	UserId        uint32 `form:"userid" binding:"required"`        //用户ID
	MiddleGoodsId uint32 `form:"middlegoodsid" binding:"required"` // 套保品种ID
}

// 查询套保品种变更记录响应
type QryMGChangeLogRsp models.ErmcpMiddleGoodsChangeLog

// @Summary 查询套保品种变更记录(菜单:套保品种/商品详情/变更记录)
// @Produce json
// @Security ApiKeyAuth
// @Param userid query int true  "所属机构ID"
// @Param middlegoodsid query int true  "套保品种id"
// @Success 200 {array} QryMGChangeLogRsp
// @Failure 500 {object} app.Response
// @Router /Ermcp/QueryMiddleGoodsChangeLog [get]
// @Tags 企业风险管理(app)
func QueryMiddleGoodsChangeLog(c *gin.Context) {
	appG := app.GinUtils{Gin: app.Gin{C: c}}
	var req QryMGChangeLogReq
	appG.DoBindReq(&req)
	m := models.ErmcpMiddleGoodsChangeLog{MIDDLEGOODSID: int(req.MiddleGoodsId)}
	appG.DoGetDataEx(&m)
}
