package controllers_join

import (
	"encoding/json"
	"kkscrap-go/locals"
	models_join "kkscrap-go/models/join"
	"net/http"

	"github.com/dabory/abango-rest"
	"github.com/labstack/echo"
)

type ChartLine2PageReq struct {
	QueryVars      locals.QueryVars
	ChartLine2Vars locals.ListType1Vars
	PageVars       locals.PageVars
}

type ChartType1PageReq struct {
	QueryVars      locals.QueryVars
	ChartLine2Vars locals.ListType1Vars
	PageVars       locals.PageVars
}

func ChartLine2Page(c echo.Context) error {

	v := c.Get("receiver").(ChartLine2PageReq)
	y := c.Get("abango").(abango.Controller)

	vRet := &struct {
		models_join.ChartLine2PageRet
	}{}

	vRet.QueryVars = v.QueryVars
	vRet.ChartLine2Vars = v.ChartLine2Vars

	if err := vRet.GetChartLine2Page(&y); err != nil {
		return c.String(607, err.Error())
	}

	ret, _ := json.Marshal(vRet)
	return c.JSONBlob(http.StatusOK, ret)
}

func ChartType1Page(c echo.Context) error {

	v := c.Get("receiver").(ChartType1PageReq)
	y := c.Get("abango").(abango.Controller)

	vRet := &struct {
		models_join.ChartType1PageRet
	}{}

	vRet.QueryVars = v.QueryVars
	vRet.ChartLine2Vars = v.ChartLine2Vars

	if err := vRet.GetChartType1Page(&y); err != nil {
		return c.String(607, err.Error())
	}

	ret, _ := json.Marshal(vRet)
	return c.JSONBlob(http.StatusOK, ret)
}
