// Copyright (c) 2024-2026 Celestino Amoroso (celestino.amoroso@gmail.com).
// All rights reserved.

// operand-selector-case.go
package expr

import (
	"git.portale-stac.it/go-pkg/expr/kern"
	"git.portale-stac.it/go-pkg/expr/scan"
	"git.portale-stac.it/go-pkg/expr/sym"
)

// -------- selector case term

type selectorCase struct {
	filterList *scan.Term
	caseExpr   kern.Expr
}

// func (sc *selectorCase) String() string {
// 	var sb strings.Builder
// 	if sc.filterList != nil {
// 		sc.filterList.ToString(&sb)
// 		sb.WriteByte(' ')
// 	}
// 	sb.WriteByte('{')
// 	sb.WriteString(sc.caseExpr.String())
// 	sb.WriteByte('}')
// 	return sb.String()
// }

func newSelectorCaseTerm(row, col int, filterList *scan.Term, caseExpr kern.Expr) *scan.Term {
	tk := scan.NewValueToken(row, col, sym.SymSelectorCase, "", &selectorCase{filterList: filterList, caseExpr: caseExpr})
	return &scan.Term{
		Tk:       *tk,
		Parent:   nil,
		Children: nil,
		Position: scan.PosLeaf,
		Priority: scan.PriValue,
		EvalFunc: evalSelectorCase,
	}
}

// -------- eval selector case
func evalSelectorCase(ctx kern.ExprContext, opTerm *scan.Term) (v any, err error) {
	v, _ = opTerm.Value().(*selectorCase)
	return
}

// func evalSelectorCase(ctx kern.ExprContext, opTerm *scan.Term) (v any, err error) {
// 	var ok bool
// 	if v, ok = opTerm.Value().(*selectorCase); !ok {
// 		err = fmt.Errorf("selector-case expected, got %T", opTerm.Value())
// 	}
// 	return
// }
