// Copyright 2026 MarketAlly. All rights reserved.
// SPDX-License-Identifier: MIT

package structs

import "time"

// WikiPageV2 represents a wiki page in v2 API format
type WikiPageV2 struct {
	Name        string        `json:"name"`
	Title       string        `json:"title"`
	Path        string        `json:"path"`
	URL         string        `json:"url"`
	HTMLURL     string        `json:"html_url"`
	Content     string        `json:"content,omitempty"`
	ContentHTML string        `json:"content_html,omitempty"`
	WordCount   int           `json:"word_count"`
	LinksOut    []string      `json:"links_out,omitempty"`
	LinksIn     []string      `json:"links_in,omitempty"`
	Sidebar     string        `json:"sidebar,omitempty"`
	Footer      string        `json:"footer,omitempty"`
	LastCommit  *WikiCommitV2 `json:"last_commit,omitempty"`
	HistoryURL  string        `json:"history_url,omitempty"`
}

// WikiCommitV2 represents a wiki commit in v2 API format
type WikiCommitV2 struct {
	SHA       string        `json:"sha"`
	Author    *WikiAuthorV2 `json:"author"`
	Committer *WikiAuthorV2 `json:"committer,omitempty"`
	Message   string        `json:"message"`
	Date      time.Time     `json:"date"`
}

// WikiAuthorV2 represents a wiki commit author
type WikiAuthorV2 struct {
	Username  string `json:"username,omitempty"`
	Name      string `json:"name"`
	Email     string `json:"email"`
	AvatarURL string `json:"avatar_url,omitempty"`
}

// WikiPageListV2 represents a list of wiki pages
type WikiPageListV2 struct {
	Pages      []*WikiPageV2 `json:"pages"`
	TotalCount int64         `json:"total_count"`
	HasMore    bool          `json:"has_more"`
}

// WikiSearchResultV2 represents a search result item
type WikiSearchResultV2 struct {
	Name        string    `json:"name"`
	Title       string    `json:"title"`
	Snippet     string    `json:"snippet"`
	Score       float32   `json:"score"`
	WordCount   int       `json:"word_count"`
	LastUpdated time.Time `json:"last_updated"`
}

// WikiSearchResponseV2 represents search results
type WikiSearchResponseV2 struct {
	Query      string                `json:"query"`
	Results    []*WikiSearchResultV2 `json:"results"`
	TotalCount int64                 `json:"total_count"`
}

// WikiGraphNodeV2 represents a node in the wiki graph
type WikiGraphNodeV2 struct {
	Name      string `json:"name"`
	Title     string `json:"title,omitempty"`
	WordCount int    `json:"word_count"`
}

// WikiGraphEdgeV2 represents an edge in the wiki graph
type WikiGraphEdgeV2 struct {
	Source string `json:"source"`
	Target string `json:"target"`
}

// WikiGraphV2 represents the wiki page relationship graph
type WikiGraphV2 struct {
	Nodes []*WikiGraphNodeV2 `json:"nodes"`
	Edges []*WikiGraphEdgeV2 `json:"edges"`
}

// WikiOrphanedPageV2 represents an orphaned page
type WikiOrphanedPageV2 struct {
	Name      string `json:"name"`
	WordCount int    `json:"word_count"`
}

// WikiDeadLinkV2 represents a dead link
type WikiDeadLinkV2 struct {
	Page       string `json:"page"`
	BrokenLink string `json:"broken_link"`
}

// WikiOutdatedPageV2 represents an outdated page
type WikiOutdatedPageV2 struct {
	Name     string    `json:"name"`
	LastEdit time.Time `json:"last_edit"`
	DaysOld  int       `json:"days_old"`
}

// WikiShortPageV2 represents a short page
type WikiShortPageV2 struct {
	Name      string `json:"name"`
	WordCount int    `json:"word_count"`
}

// WikiTopLinkedPageV2 represents a highly linked page
type WikiTopLinkedPageV2 struct {
	Name          string `json:"name"`
	IncomingLinks int    `json:"incoming_links"`
}

// WikiHealthV2 represents wiki health metrics
type WikiHealthV2 struct {
	OrphanedPages []*WikiOrphanedPageV2 `json:"orphaned_pages"`
	DeadLinks     []*WikiDeadLinkV2     `json:"dead_links"`
	OutdatedPages []*WikiOutdatedPageV2 `json:"outdated_pages"`
	ShortPages    []*WikiShortPageV2    `json:"short_pages"`
}

// WikiStatsV2 represents wiki statistics
type WikiStatsV2 struct {
	TotalPages   int64                  `json:"total_pages"`
	TotalWords   int64                  `json:"total_words"`
	TotalCommits int64                  `json:"total_commits"`
	LastUpdated  time.Time              `json:"last_updated"`
	Contributors int64                  `json:"contributors"`
	Health       *WikiHealthV2          `json:"health"`
	TopLinked    []*WikiTopLinkedPageV2 `json:"top_linked"`
}

// WikiRevisionV2 represents a page revision
type WikiRevisionV2 struct {
	SHA       string        `json:"sha"`
	Author    *WikiAuthorV2 `json:"author"`
	Message   string        `json:"message"`
	Date      time.Time     `json:"date"`
	Additions int           `json:"additions,omitempty"`
	Deletions int           `json:"deletions,omitempty"`
}

// WikiRevisionsV2 represents page revision history
type WikiRevisionsV2 struct {
	PageName   string            `json:"page_name"`
	Revisions  []*WikiRevisionV2 `json:"revisions"`
	TotalCount int64             `json:"total_count"`
}

// CreateWikiPageV2Option represents options for creating a wiki page
type CreateWikiPageV2Option struct {
	Name    string `json:"name" binding:"Required"`
	Title   string `json:"title"`
	Content string `json:"content" binding:"Required"`
	Message string `json:"message"`
}

// UpdateWikiPageV2Option represents options for updating a wiki page
type UpdateWikiPageV2Option struct {
	Title    string `json:"title"`
	Content  string `json:"content"`
	Message  string `json:"message"`
	RenameTo string `json:"rename_to,omitempty"`
}

// DeleteWikiPageV2Option represents options for deleting a wiki page
type DeleteWikiPageV2Option struct {
	Message string `json:"message"`
}

// WikiDeleteResponseV2 represents delete response
type WikiDeleteResponseV2 struct {
	Success bool `json:"success"`
}
