// Package nuxtdocs provides parsing and extraction for Nuxt documentation
// from nuxt.com/docs/.
package nuxtdocs

import "time"

// Reference represents the Nuxt API reference.
type Reference struct {
	Version     string        `json:"version"`
	DocURL      string        `json:"doc_url"`
	Components  []*Component  `json:"components,omitempty"`
	Composables []*Composable `json:"composables,omitempty"`
	Utilities   []*Utility    `json:"utilities,omitempty"`
	Configs     []*Config     `json:"configs,omitempty"`
	Commands    []*Command    `json:"commands,omitempty"`
	FetchedAt   time.Time     `json:"fetched_at"`
}

// Component represents a Nuxt component.
type Component struct {
	Name       string     `json:"name"`
	Doc        string     `json:"doc,omitempty"`
	Props      []*Prop    `json:"props,omitempty"`
	Slots      []*Slot    `json:"slots,omitempty"`
	Events     []*Event   `json:"events,omitempty"`
	Examples   []*Example `json:"examples,omitempty"`
	Category   string     `json:"category,omitempty"`
	DocURL     string     `json:"doc_url"`
	Deprecated string     `json:"deprecated,omitempty"`
}

// Prop represents a component prop.
type Prop struct {
	Name       string `json:"name"`
	Type       string `json:"type,omitempty"`
	Doc        string `json:"doc,omitempty"`
	Required   bool   `json:"required"`
	Default    string `json:"default,omitempty"`
	Deprecated string `json:"deprecated,omitempty"`
}

// Slot represents a component slot.
type Slot struct {
	Name  string `json:"name"`
	Doc   string `json:"doc,omitempty"`
	Props string `json:"props,omitempty"`
}

// Event represents a component event.
type Event struct {
	Name       string       `json:"name"`
	Doc        string       `json:"doc,omitempty"`
	Parameters []*Parameter `json:"parameters,omitempty"`
}

// Composable represents a Nuxt composable.
type Composable struct {
	Name       string       `json:"name"`
	Doc        string       `json:"doc,omitempty"`
	Signature  string       `json:"signature,omitempty"`
	Parameters []*Parameter `json:"parameters,omitempty"`
	Returns    string       `json:"returns,omitempty"`
	Examples   []*Example   `json:"examples,omitempty"`
	Category   string       `json:"category,omitempty"` // data, state, routing, etc.
	DocURL     string       `json:"doc_url"`
	Deprecated string       `json:"deprecated,omitempty"`
}

// Utility represents a Nuxt utility function.
type Utility struct {
	Name       string       `json:"name"`
	Doc        string       `json:"doc,omitempty"`
	Signature  string       `json:"signature,omitempty"`
	Parameters []*Parameter `json:"parameters,omitempty"`
	Returns    string       `json:"returns,omitempty"`
	Examples   []*Example   `json:"examples,omitempty"`
	DocURL     string       `json:"doc_url"`
	Deprecated string       `json:"deprecated,omitempty"`
}

// Config represents a Nuxt configuration option.
type Config struct {
	Name       string      `json:"name"`
	Doc        string      `json:"doc,omitempty"`
	Type       string      `json:"type,omitempty"`
	Default    string      `json:"default,omitempty"`
	Properties []*Property `json:"properties,omitempty"`
	Examples   []*Example  `json:"examples,omitempty"`
	Category   string      `json:"category,omitempty"`
	DocURL     string      `json:"doc_url"`
	Deprecated string      `json:"deprecated,omitempty"`
}

// Property represents a nested config property.
type Property struct {
	Name       string      `json:"name"`
	Doc        string      `json:"doc,omitempty"`
	Type       string      `json:"type,omitempty"`
	Default    string      `json:"default,omitempty"`
	Properties []*Property `json:"properties,omitempty"`
	Deprecated string      `json:"deprecated,omitempty"`
}

// Command represents a Nuxt CLI command.
type Command struct {
	Name      string      `json:"name"`
	Doc       string      `json:"doc,omitempty"`
	Usage     string      `json:"usage,omitempty"`
	Flags     []*Flag     `json:"flags,omitempty"`
	Arguments []*Argument `json:"arguments,omitempty"`
	Examples  []*Example  `json:"examples,omitempty"`
	DocURL    string      `json:"doc_url"`
}

// Flag represents a command flag.
type Flag struct {
	Name     string `json:"name"`
	Doc      string `json:"doc,omitempty"`
	Type     string `json:"type,omitempty"`
	Default  string `json:"default,omitempty"`
	Required bool   `json:"required"`
	Short    string `json:"short,omitempty"`
}

// Argument represents a command argument.
type Argument struct {
	Name     string `json:"name"`
	Doc      string `json:"doc,omitempty"`
	Type     string `json:"type,omitempty"`
	Required bool   `json:"required"`
	Default  string `json:"default,omitempty"`
}

// Parameter represents a function parameter.
type Parameter struct {
	Name     string `json:"name"`
	Type     string `json:"type,omitempty"`
	Doc      string `json:"doc,omitempty"`
	Optional bool   `json:"optional"`
	Default  string `json:"default,omitempty"`
}

// Example represents a code example.
type Example struct {
	Title       string `json:"title,omitempty"`
	Code        string `json:"code"`
	Description string `json:"description,omitempty"`
	Language    string `json:"language,omitempty"`
}

// SearchResult represents a search result.
type SearchResult struct {
	Name       string `json:"name"`
	Kind       string `json:"kind"` // component, composable, utility, config, command
	Doc        string `json:"doc,omitempty"`
	DocURL     string `json:"doc_url"`
	Score      int    `json:"score"`
	Deprecated bool   `json:"deprecated"`
}
