package test_data

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

type IReportChartService interface {
}

type ReportChartService struct{}

func InitReportChartService() *ReportChartService {
	return &ReportChartService{}
}

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

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

// @Tags 数据分析平台-生产
// @Summary 测试良率-按供应商
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.PassProbabilityByFactory true "查询参数"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"操作成功"}"
// @Router /testData/report/fTPassProbabilityByFactory [post]
func (S *ReportChartService) FTPassProbabilityByFactory(c *gin.Context) {
	r := request.PassProbabilityByFactory{}
	_ = c.ShouldBind(&r)
	if msg, ok := utils.ValidateInfo2CN(r); !ok {
		response.FailWithMessage(msg, c)
		return
	}
	lines, histogram, max, min := test_data.PassProbabilityByFactory(&r)
	response.OkWithData(gin.H{"lines": lines, "histogram": histogram, "max": max, "min": min}, c)
}

// @Tags 数据分析平台-生产
// @Summary 测试良率-按产品型号
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.PassProbabilityByProduct true "查询参数"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"操作成功"}"
// @Router /testData/report/fTPassProbabilityByProduct [post]
func (S *ReportChartService) FTPassProbabilityByProduct(c *gin.Context) {
	r := request.PassProbabilityByProduct{}
	_ = c.ShouldBind(&r)
	if msg, ok := utils.ValidateInfo2CN(r); !ok {
		response.FailWithMessage(msg, c)
		return
	}
	lines, histogram, binLines, binHistogram := test_data.FTPassProbabilityByProduct(&r)
	response.OkWithData(gin.H{"lines": lines, "histogram": histogram, "bin_lines": binLines, "bin_histogram": binHistogram}, c)
}
