package registry

import (
	"embed"
	"fmt"
	"path/filepath"
	"strings"
)

//go:embed schema-org/*.json
var schemasFS embed.FS

func GetSchemas() ([][]byte, error) {
	entries, err := schemasFS.ReadDir("schema-org")
	if err != nil {
		return nil, fmt.Errorf("read schema directory: %w", err)
	}

	var out [][]byte

	for _, e := range entries {
		if e.IsDir() || !strings.HasSuffix(e.Name(), ".json") {
			continue
		}
		raw, err := schemasFS.ReadFile(filepath.ToSlash("schema-org/" + e.Name()))
		if err != nil {
			return nil, fmt.Errorf("read %s: %w", e.Name(), err)
		}
		out = append(out, raw)
	}

	return out, nil
}
