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 PopupList1PageReq struct {
	QueryVars      locals.QueryVars
	PopupList1Vars locals.PopupList1Vars
	ListType1Vars  locals.ListType1Vars
	PageVars       locals.PageVars
}

func PopupList1Page(c echo.Context) error {

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

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

	vRet.QueryVars = v.QueryVars
	vRet.ListType1Vars = v.ListType1Vars
	vRet.PopupList1Vars = v.PopupList1Vars
	vRet.PageVars = v.PageVars

	if v.ListType1Vars.IsDownloadList == false {
		if err := vRet.GetPopupList1PagePlain(&y); err != nil {
			return c.String(607, err.Error())
		}
	} else if v.ListType1Vars.IsDownloadList == true {
		if err := vRet.GetPopupList1PageTmp(&y); err != nil {
			return c.String(607, err.Error())
		}
	}

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