package awardref

// Preset is a ready-made reference list a user can apply to an award in one
// click (Canadian provinces, US states, …). Codes match the values that land
// in the corresponding QSO field (e.g. ADIF STATE codes).
type Preset struct {
	Key   string `json:"key"`   // stable id, e.g. "ca_provinces"
	Name  string `json:"name"`  // friendly label
	Field string `json:"field"` // suggested QSO field to scan
	DXCC  int    `json:"dxcc"`  // suggested DXCC scope (0 = none)
	Refs  []Ref  `json:"refs"`
}

// Presets is the catalogue of built-in reference lists, returned to the UI.
func Presets() []Preset {
	return []Preset{
		caProvinces(),
		usStates(),
	}
}

// PresetByKey returns a preset by its key (ok=false if unknown).
func PresetByKey(key string) (Preset, bool) {
	for _, p := range Presets() {
		if p.Key == key {
			return p, true
		}
	}
	return Preset{}, false
}

func ref(code, name string, dxcc int) Ref {
	return Ref{Code: code, Name: name, DXCC: dxcc, Valid: true}
}

// caProvinces — RAC Canadian Provinces (DXCC 1 = Canada). Codes are ADIF STATE
// values for VE provinces/territories.
func caProvinces() Preset {
	const ca = 1
	return Preset{
		Key: "ca_provinces", Name: "Canadian Provinces (RAC)", Field: "state", DXCC: ca,
		Refs: []Ref{
			ref("AB", "Alberta", ca), ref("BC", "British Columbia", ca),
			ref("MB", "Manitoba", ca), ref("NB", "New Brunswick", ca),
			ref("NL", "Newfoundland and Labrador", ca), ref("NS", "Nova Scotia", ca),
			ref("NT", "Northwest Territories", ca), ref("NU", "Nunavut", ca),
			ref("ON", "Ontario", ca), ref("PE", "Prince Edward Island", ca),
			ref("QC", "Quebec", ca), ref("SK", "Saskatchewan", ca),
			ref("YT", "Yukon", ca),
		},
	}
}

// usStates — Worked All States (DXCC 291 = United States). 50 ADIF STATE codes.
func usStates() Preset {
	const us = 291
	codes := [][2]string{
		{"AL", "Alabama"}, {"AK", "Alaska"}, {"AZ", "Arizona"}, {"AR", "Arkansas"},
		{"CA", "California"}, {"CO", "Colorado"}, {"CT", "Connecticut"}, {"DE", "Delaware"},
		{"FL", "Florida"}, {"GA", "Georgia"}, {"HI", "Hawaii"}, {"ID", "Idaho"},
		{"IL", "Illinois"}, {"IN", "Indiana"}, {"IA", "Iowa"}, {"KS", "Kansas"},
		{"KY", "Kentucky"}, {"LA", "Louisiana"}, {"ME", "Maine"}, {"MD", "Maryland"},
		{"MA", "Massachusetts"}, {"MI", "Michigan"}, {"MN", "Minnesota"}, {"MS", "Mississippi"},
		{"MO", "Missouri"}, {"MT", "Montana"}, {"NE", "Nebraska"}, {"NV", "Nevada"},
		{"NH", "New Hampshire"}, {"NJ", "New Jersey"}, {"NM", "New Mexico"}, {"NY", "New York"},
		{"NC", "North Carolina"}, {"ND", "North Dakota"}, {"OH", "Ohio"}, {"OK", "Oklahoma"},
		{"OR", "Oregon"}, {"PA", "Pennsylvania"}, {"RI", "Rhode Island"}, {"SC", "South Carolina"},
		{"SD", "South Dakota"}, {"TN", "Tennessee"}, {"TX", "Texas"}, {"UT", "Utah"},
		{"VT", "Vermont"}, {"VA", "Virginia"}, {"WA", "Washington"}, {"WV", "West Virginia"},
		{"WI", "Wisconsin"}, {"WY", "Wyoming"},
	}
	refs := make([]Ref, 0, len(codes))
	for _, c := range codes {
		refs = append(refs, ref(c[0], c[1], us))
	}
	return Preset{Key: "us_states", Name: "US States (WAS)", Field: "state", DXCC: us, Refs: refs}
}
