package test_data

import (
	"github.com/gin-gonic/gin"
	"testData/global"
	"testData/model"
	"testData/model/response"
	test_data "testData/repository/test.data"
	"testData/request"
	"testData/utils"
)

type IReportListService interface {
}

type ReportListService struct{}

func InitReportService() *ReportListService {
	global.PostGreSQL.AutoMigrate(&model.Report{}, &model.FinalReport{}, &model.ReportSites{}, &model.BinFail{})
	return &ReportListService{}
}

// @Tags 数据分析平台-生产
// @Summary 晶圆记录
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.WaferList true "查询参数"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"操作成功"}"
// @Router /testData/report/wafer [post]
func (S *ReportListService) WaferList(c *gin.Context) {
	r := request.WaferList{}
	_ = c.ShouldBind(&r)
	if msg, ok := utils.ValidateInfo2CN(r); !ok {
		response.FailWithMessage(msg, c)
		return
	}
	response.OkWithData(test_data.WaferList(&r), c)
}

// @Tags 数据分析平台-生产
// @Summary CP记录
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.CPList true "查询参数"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"操作成功"}"
// @Router /testData/report/cp [post]
func (S *ReportListService) CPList(c *gin.Context) {
	r := request.CPList{}
	_ = c.ShouldBind(&r)
	if msg, ok := utils.ValidateInfo2CN(r); !ok {
		response.FailWithMessage(msg, c)
		return
	}
	list, total := test_data.CPList(&r)
	response.OkWithData(gin.H{"list": list, "total": total}, c)
}

// @Tags 数据分析平台-生产
// @Summary 封装记录
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.ABList true "查询参数"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"操作成功"}"
// @Router /testData/report/ab [post]
func (S *ReportListService) ABList(c *gin.Context) {
	r := request.ABList{}
	_ = c.ShouldBind(&r)
	if msg, ok := utils.ValidateInfo2CN(r); !ok {
		response.FailWithMessage(msg, c)
		return
	}
	response.OkWithData(test_data.ABList(&r), c)
}

// @Tags 数据分析平台-生产
// @Summary FT记录
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.FTList true "查询参数"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"操作成功"}"
// @Router /testData/report/ft [post]
func (S *ReportListService) FTList(c *gin.Context) {
	r := request.FTList{}
	_ = c.ShouldBind(&r)
	if msg, ok := utils.ValidateInfo2CN(r); !ok {
		response.FailWithMessage(msg, c)
		return
	}
	list, total := test_data.FTList(&r)
	response.OkWithData(gin.H{"list": list, "total": total}, c)
}
