package controllers_join

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

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

type ItemSearchPageReq struct {
	QueryVars      locals.QueryVars
	ItemSearchVars locals.ItemSearchVars
	PageVars       locals.PageVars
}

func ItemSearchPage(c echo.Context) error {

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

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

	vRet.QueryVars = v.QueryVars
	vRet.ItemSearchVars = v.ItemSearchVars
	vRet.PageVars = v.PageVars
	// fmt.Println(vRet)

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

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