// Package vuedocs provides parsing and extraction for Vue.js documentation
// from vuejs.org/api/.
package vuedocs

import "time"

// Reference represents the Vue API reference.
type Reference struct {
	Version      string         `json:"version"`
	DocURL       string         `json:"doc_url"`
	GlobalAPI    []*API         `json:"global_api,omitempty"`
	Composition  []*Composition `json:"composition,omitempty"`
	Options      []*Options     `json:"options,omitempty"`
	Directives   []*Directive   `json:"directives,omitempty"`
	Components   []*Component   `json:"components,omitempty"`
	SpecialAttrs []*SpecialAttr `json:"special_attrs,omitempty"`
	FetchedAt    time.Time      `json:"fetched_at"`
}

// API represents a Vue global API.
type API 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"`
	DocURL     string       `json:"doc_url"`
	Deprecated string       `json:"deprecated,omitempty"`
}

// Composition represents a Composition API function.
type Composition struct {
	Name       string       `json:"name"`
	Kind       string       `json:"kind,omitempty"` // ref, reactive, computed, watch, lifecycle
	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"`
}

// Options represents an Options API property.
type Options struct {
	Name       string     `json:"name"`
	Doc        string     `json:"doc,omitempty"`
	Type       string     `json:"type,omitempty"`
	Default    string     `json:"default,omitempty"`
	Examples   []*Example `json:"examples,omitempty"`
	Category   string     `json:"category,omitempty"` // state, lifecycle, rendering
	DocURL     string     `json:"doc_url"`
	Deprecated string     `json:"deprecated,omitempty"`
}

// Directive represents a Vue directive.
type Directive struct {
	Name       string      `json:"name"`
	Doc        string      `json:"doc,omitempty"`
	Usage      string      `json:"usage,omitempty"`
	Arguments  []*Argument `json:"arguments,omitempty"`
	Modifiers  []*Modifier `json:"modifiers,omitempty"`
	Examples   []*Example  `json:"examples,omitempty"`
	DocURL     string      `json:"doc_url"`
	Deprecated string      `json:"deprecated,omitempty"`
}

// Argument represents a directive argument.
type Argument struct {
	Name string `json:"name"`
	Doc  string `json:"doc,omitempty"`
}

// Modifier represents a directive modifier.
type Modifier struct {
	Name string `json:"name"`
	Doc  string `json:"doc,omitempty"`
}

// Component represents a Vue built-in component.
type Component struct {
	Name       string     `json:"name"`
	Doc        string     `json:"doc,omitempty"`
	Props      []*Prop    `json:"props,omitempty"`
	Events     []*Event   `json:"events,omitempty"`
	Slots      []*Slot    `json:"slots,omitempty"`
	Examples   []*Example `json:"examples,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"`
}

// Event represents a component event.
type Event struct {
	Name       string       `json:"name"`
	Doc        string       `json:"doc,omitempty"`
	Parameters []*Parameter `json:"parameters,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"` // slot props type
	Default bool   `json:"default"`
}

// SpecialAttr represents a special Vue attribute.
type SpecialAttr struct {
	Name       string     `json:"name"`
	Doc        string     `json:"doc,omitempty"`
	Usage      string     `json:"usage,omitempty"`
	Examples   []*Example `json:"examples,omitempty"`
	DocURL     string     `json:"doc_url"`
	Deprecated string     `json:"deprecated,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"` // api, composition, options, directive, component
	Doc        string `json:"doc,omitempty"`
	DocURL     string `json:"doc_url"`
	Score      int    `json:"score"`
	Deprecated bool   `json:"deprecated"`
}
