// Package springdocs provides parsing and extraction for Spring Boot documentation
// from docs.spring.io.
package springdocs

import "time"

// Module represents a Spring module's documentation.
type Module struct {
	Name       string      `json:"name"`
	Doc        string      `json:"doc,omitempty"`
	Version    string      `json:"version,omitempty"`
	DocURL     string      `json:"doc_url"`
	Packages   []*Package  `json:"packages,omitempty"`
	Classes    []*Class    `json:"classes,omitempty"`
	Guides     []*Guide    `json:"guides,omitempty"`
	Properties []*Property `json:"properties,omitempty"`
	FetchedAt  time.Time   `json:"fetched_at"`
}

// Package represents a Spring package.
type Package struct {
	Name    string   `json:"name"`
	Doc     string   `json:"doc,omitempty"`
	Classes []*Class `json:"classes,omitempty"`
	DocURL  string   `json:"doc_url"`
}

// Class represents a Spring class.
type Class struct {
	QualifiedName string    `json:"qualified_name"`
	Name          string    `json:"name"`
	Package       string    `json:"package"`
	Kind          string    `json:"kind"`
	Doc           string    `json:"doc,omitempty"`
	Annotations   []string  `json:"annotations,omitempty"`
	SuperClass    string    `json:"super_class,omitempty"`
	Interfaces    []string  `json:"interfaces,omitempty"`
	Fields        []*Field  `json:"fields,omitempty"`
	Methods       []*Method `json:"methods,omitempty"`
	Constructors  []*Method `json:"constructors,omitempty"`
	DocURL        string    `json:"doc_url"`
	Since         string    `json:"since,omitempty"`
}

// Field represents a class field.
type Field struct {
	Name        string   `json:"name"`
	Type        string   `json:"type"`
	Doc         string   `json:"doc,omitempty"`
	Annotations []string `json:"annotations,omitempty"`
	DocURL      string   `json:"doc_url"`
}

// Method represents a method.
type Method struct {
	Name          string       `json:"name"`
	Doc           string       `json:"doc,omitempty"`
	Annotations   []string     `json:"annotations,omitempty"`
	ReturnType    string       `json:"return_type,omitempty"`
	Parameters    []*Parameter `json:"parameters,omitempty"`
	Signature     string       `json:"signature"`
	QualifiedName string       `json:"qualified_name"`
	DocURL        string       `json:"doc_url"`
	IsConstructor bool         `json:"is_constructor"`
}

// Parameter represents a method parameter.
type Parameter struct {
	Name string `json:"name"`
	Type string `json:"type"`
	Doc  string `json:"doc,omitempty"`
}

// Guide represents a Spring guide/tutorial.
type Guide struct {
	Title       string   `json:"title"`
	Description string   `json:"description,omitempty"`
	DocURL      string   `json:"doc_url"`
	Tags        []string `json:"tags,omitempty"`
	Level       string   `json:"level,omitempty"` // beginner, intermediate, advanced
}

// Property represents a Spring configuration property.
type Property struct {
	Name       string `json:"name"`
	Value      string `json:"value,omitempty"`
	Type       string `json:"type,omitempty"`
	Doc        string `json:"doc,omitempty"`
	Default    string `json:"default,omitempty"`
	DocURL     string `json:"doc_url"`
	Deprecated string `json:"deprecated,omitempty"`
}

// SearchResult represents a search result.
type SearchResult struct {
	Name   string `json:"name"`
	Kind   string `json:"kind"` // class, method, property, guide
	Module string `json:"module,omitempty"`
	Doc    string `json:"doc,omitempty"`
	DocURL string `json:"doc_url"`
	Score  int    `json:"score"`
}
