package test_data

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

type ITestService interface {
}

type TestService struct{}

func InitTestService() *TestService {
	return &TestService{}
}

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

// @Tags 数据分析平台
// @Summary 直方图
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.Histogram true "直方图"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"操作成功"}"
// @Router /testData/histogram [post]
func (S *TestService) Histogram(c *gin.Context) {
	r := request.Histogram{}
	_ = c.ShouldBind(&r)
	if msg, ok := utils.ValidateInfo2CN(r); !ok {
		response.FailWithMessage(msg, c)
		return
	}
	data, err := test_data.Histogram(&r)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	response.OkWithData(gin.H{"data": data}, c)
}

// @Tags 数据分析平台
// @Summary 散点图
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.Scatter true "散点图"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"操作成功"}"
// @Router /testData/scatter [post]
func (S *TestService) Scatter(c *gin.Context) {
	r := request.Scatter{}
	_ = c.ShouldBind(&r)
	if msg, ok := utils.ValidateInfo2CN(r); !ok {
		response.FailWithMessage(msg, c)
		return
	}
	data, x, y, err := test_data.Scatter(&r)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	response.OkWithData(gin.H{"data": data, "x": x, "y": y}, c)
}

// @Tags 数据分析平台
// @Summary 饼状图
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.Pie true "饼状图"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"操作成功"}"
// @Router /testData/pie [post]
func (S *TestService) Pie(c *gin.Context) {
	r := request.Pie{}
	_ = c.ShouldBind(&r)
	if msg, ok := utils.ValidateInfo2CN(r); !ok {
		response.FailWithMessage(msg, c)
		return
	}
	data, err := test_data.Pie(&r)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	response.OkWithData(data, c)
}

// @Tags 数据分析平台
// @Summary 折线图
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.Line true "折线图"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"操作成功"}"
// @Router /testData/line [post]
func (S *TestService) Line(c *gin.Context) {
	r := request.Line{}
	_ = c.ShouldBind(&r)
	if msg, ok := utils.ValidateInfo2CN(r); !ok {
		response.FailWithMessage(msg, c)
		return
	}
	data, err := test_data.Line(&r)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	response.OkWithData(data, c)
}

// @Tags 数据分析平台
// @Summary CP Map图
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.CPMap true "CP Map图"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"操作成功"}"
// @Router /testData/cpMap [post]
func (S *TestService) CPMap(c *gin.Context) {
	r := request.CPMap{}
	_ = c.ShouldBind(&r)
	if msg, ok := utils.ValidateInfo2CN(r); !ok {
		response.FailWithMessage(msg, c)
		return
	}
	res, err := test_data.CPMap(&r)
	if err != nil {
		response.FailWithMessage(err.Error(), c)
		return
	}
	response.OkWithData(res, c)
}

// @Tags 数据分析平台
// @Summary 导出CP Map图
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.CPMap true "CP Map图"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"操作成功"}"
// @Router /testData/cpMap/export [post]
func (S *TestService) CPMapExport(c *gin.Context) {
	r := request.CPMap{}
	_ = c.ShouldBind(&r)
	if msg, ok := utils.ValidateInfo2CN(r); !ok {
		response.FailWithMessage(msg, c)
		return
	}
	response.OkWithData(test_data.ExportCPMap(&r), c)
}

// @Tags 数据分析平台
// @Summary 导出直方图
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.Histogram true "CP Map图"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"操作成功"}"
// @Router /testData/ftHistogram/export [post]
func (S *TestService) ExportHistogram(c *gin.Context) {
	r := request.Histogram{}
	_ = c.ShouldBind(&r)
	if msg, ok := utils.ValidateInfo2CN(r); !ok {
		response.FailWithMessage(msg, c)
		return
	}
	response.OkWithData(test_data.ExportHistogram(&r), c)
}

// @Tags 数据分析平台
// @Summary 导出散点图
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.Scatter true "CP Map图"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"操作成功"}"
// @Router /testData/scatter/export [post]
func (S *TestService) ExportScatter(c *gin.Context) {
	r := request.Scatter{}
	_ = c.ShouldBind(&r)
	if msg, ok := utils.ValidateInfo2CN(r); !ok {
		response.FailWithMessage(msg, c)
		return
	}
	response.OkWithData(test_data.ExportScatter(&r), c)
}

// @Tags 数据分析平台
// @Summary Log各Site差异图
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.LogSiteChart true "Log各Site差异图"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"操作成功"}"
// @Router /testData/logSite [post]
func (S *TestService) LogSite(c *gin.Context) {
	r := request.LogSiteChart{}
	_ = c.ShouldBind(&r)
	if msg, ok := utils.ValidateInfo2CN(r); !ok {
		response.FailWithMessage(msg, c)
		return
	}
	response.OkWithData(test_data.LogSiteChart(&r), c)
}

// @Tags 数据分析平台
// @Summary 参数极限
// @Security ApiKeyAuth
// @accept application/json
// @Produce application/json
// @Param data body request.SelectionLimit true "参数极限"
// @Success 200 {string} string "{"success":true,"data":{},"msg":"操作成功"}"
// @Router /testData/selection/limit [post]
func (S *TestService) SelectionLimit(c *gin.Context) {
	r := request.SelectionLimit{}
	_ = c.ShouldBind(&r)
	if msg, ok := utils.ValidateInfo2CN(r); !ok {
		response.FailWithMessage(msg, c)
		return
	}
	max, min := test_data.SelectionLimit(&r)
	response.OkWithData(gin.H{"max": max, "min": min}, c)
}
