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 SelectType1PageReq struct {
	QueryVars locals.QueryVars
	// SetupVars       []locals.SetupBase
	SelectType1Vars locals.SelectType1Vars
	PageVars        locals.PageVars
}

func SelectType1Page(c echo.Context) error {

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

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

	// fmt.Println(v)
	// var vRet models_join.SelectType1PageRet

	vRet.QueryVars = v.QueryVars
	// vRet.SetupVars = v.SetupVars
	vRet.SelectType1Vars = v.SelectType1Vars
	vRet.PageVars = v.PageVars

	// r := c.Request().URL.Path
	sqlDir := "select"

	//당분간 아래 지우지 말것
	// if v.SelectType1Vars.IsDownloadList == false {
	// 	if err := vRet.GetSelectType1PagePlain(&y, sqlDir); err != nil {
	// 		return c.String(607, err.Error())
	// 	}
	// } else if v.SelectType1Vars.IsDownloadList == true {
	if err := vRet.GetSelectType1PageTmp(&y, sqlDir); err != nil {
		return c.String(607, err.Error())
	}
	// }

	// if len(vRet.SetupVars) != 0 {
	// 	if err := controllers_func.SetupJsonArrayGet(&y, &vRet); err != nil {
	// 		return c.String(607, err.Error())
	// 	}
	// }

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