package main

import (
	"fmt"
	"os"
)

func usage() {
	fmt.Fprint(os.Stderr, `preseem - CLI for the Preseem Model API at $PRESEEM_URL (default `+defaultBaseURL+`)

Auth:  export PRESEEM_KEY=<api key>  (HTTP Basic, key as username, empty password)

Resources (read-only):
  accounts   list | get <id>
  ap         list | get <id>            (access points)
  ap-config  get  <id>
  ap-scores
  cpe-scores
  packages   list | get <id>
  services   list | get <id>
  routers    list | get <id>
  olts       list | get <id>
  sites      list | get <id>

Write operations:
  clear-services  [--dry-run | --confirm] [--account <id>]
                  delete all services (MACs) from all accounts
                  --dry-run: preview only; --confirm: actually delete
                  --account: limit to a single account ID

Common flags:
  list:  [--json] [--page N] [--limit 100..1000]
         (no --page = auto-paginate; --json + auto = merged data envelope)
  get:   [--json]

Examples:
  preseem accounts list
  preseem ap list --json | jq '.data[].name'
  preseem ap get 123
  preseem ap-scores
  preseem sites list --page 1 --limit 100
`)
}

func main() {
	if len(os.Args) < 2 {
		usage()
		os.Exit(2)
	}
	var err error
	switch os.Args[1] {
	case "accounts":
		err = cmdAccounts(os.Args[2:])
	case "ap":
		err = cmdAP(os.Args[2:])
	case "ap-config":
		err = cmdAPConfig(os.Args[2:])
	case "ap-scores":
		err = cmdAPScores(os.Args[2:])
	case "cpe-scores":
		err = cmdCPEScores(os.Args[2:])
	case "packages":
		err = cmdPackages(os.Args[2:])
	case "services":
		err = cmdServices(os.Args[2:])
	case "routers":
		err = cmdRouters(os.Args[2:])
	case "olts":
		err = cmdOLTs(os.Args[2:])
	case "sites":
		err = cmdSites(os.Args[2:])
	case "clear-services":
		err = cmdClearServices(os.Args[2:])
	case "-h", "--help", "help":
		usage()
		return
	default:
		usage()
		os.Exit(2)
	}
	if err != nil {
		fmt.Fprintln(os.Stderr, "error:", err)
		os.Exit(1)
	}
}
