// Package reactdocs provides parsing and extraction for React documentation
// from react.dev.
package reactdocs

import "time"

// Reference represents the React API reference.
type Reference struct {
	Version    string       `json:"version"`
	DocURL     string       `json:"doc_url"`
	Hooks      []*Hook      `json:"hooks,omitempty"`
	Components []*Component `json:"components,omitempty"`
	APIs       []*API       `json:"apis,omitempty"`
	Directives []*Directive `json:"directives,omitempty"`
	FetchedAt  time.Time    `json:"fetched_at"`
}

// Hook represents a React hook.
type Hook struct {
	Name       string       `json:"name"`
	Doc        string       `json:"doc,omitempty"`
	Signature  string       `json:"signature,omitempty"`
	Parameters []*Parameter `json:"parameters,omitempty"`
	Returns    []*Return    `json:"returns,omitempty"`
	Examples   []*Example   `json:"examples,omitempty"`
	Category   string       `json:"category,omitempty"` // state, effect, ref, etc.
	DocURL     string       `json:"doc_url"`
	Deprecated string       `json:"deprecated,omitempty"`
}

// Component represents a React built-in component.
type Component struct {
	Name       string     `json:"name"`
	Doc        string     `json:"doc,omitempty"`
	Props      []*Prop    `json:"props,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"`
	Doc        string `json:"doc,omitempty"`
	Required   bool   `json:"required"`
	Default    string `json:"default,omitempty"`
	Deprecated string `json:"deprecated,omitempty"`
}

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

// Directive represents a React directive (like 'use client', 'use server').
type Directive 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"`
}

// 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"`
}

// Return represents a return value.
type Return struct {
	Name string `json:"name,omitempty"`
	Type string `json:"type,omitempty"`
	Doc  string `json:"doc,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"` // hook, component, api, directive
	Doc        string `json:"doc,omitempty"`
	DocURL     string `json:"doc_url"`
	Score      int    `json:"score"`
	Deprecated bool   `json:"deprecated"`
}
