/*
/*
 * Copyright (c) 2024 Augur AI, Inc.
 * This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0. 
 * If a copy of the MPL was not distributed with this file, you can obtain one at https://mozilla.org/MPL/2.0/.
 *
 
 * Copyright (c) 2024 Augur AI, Inc.
 *
 * This file is licensed under the Augur AI Proprietary License.
 *
 * Attribution:
 * This work is based on code from https://github.com/hofstadter-io/hof, licensed under the Apache License 2.0.
 */

package structural

import (
	"fmt"

	"cuelang.org/go/cue"
)

type Options struct {
	AllTypeErrors  bool
	NodeTypeErrors bool
}

func newAny(ctx *cue.Context) cue.Value {
	return ctx.CompileString("_")
}

func newStruct(ctx *cue.Context) cue.Value {
	return ctx.CompileString("{...}")
}

type listProc int

const (
	LIST_ERR listProc = iota // unknown arg
	LIST_AND                 // all apply
	LIST_OR                  // any apply
	LIST_PER                 // pairwise
)

func getListProcType(val cue.Value) (listProc, error) {
	attr := val.Attribute("list")
	// no attribute or no arg, so default is LIST_AND
	if attr.Err() != nil || attr.NumArgs() == 0 {
		return LIST_AND, nil
	}
	a, err := attr.String(0)
	if err != nil {
		return LIST_ERR, err
	}
	// otherwise, check what arg we have
	switch a {
	case "and", "":
		return LIST_AND, nil
	case "or":
		return LIST_OR, nil
	case "pairwise", "per":
		return LIST_PER, nil
	default:
		return LIST_ERR, fmt.Errorf("Unknown list processing type %q at %v", a, val.Pos())
	}
}

func GetLabel(val cue.Value) cue.Selector {
	ss := val.Path().Selectors()
	s := ss[len(ss)-1]
	return s
}
