package types

import (
	"time"

	"github.com/google/uuid"
)

type ThoughtMetadata struct {
	People                  []string            `json:"people"`
	ActionItems             []string            `json:"action_items"`
	DatesMentioned          []string            `json:"dates_mentioned"`
	Topics                  []string            `json:"topics"`
	Type                    string              `json:"type"`
	Source                  string              `json:"source"`
	Attachments             []ThoughtAttachment `json:"attachments,omitempty"`
	MetadataStatus          string              `json:"metadata_status,omitempty"`
	MetadataUpdatedAt       string              `json:"metadata_updated_at,omitempty"`
	MetadataLastAttemptedAt string              `json:"metadata_last_attempted_at,omitempty"`
	MetadataError           string              `json:"metadata_error,omitempty"`
}

type ThoughtAttachment struct {
	FileID    uuid.UUID `json:"file_id"`
	Name      string    `json:"name"`
	MediaType string    `json:"media_type"`
	Kind      string    `json:"kind,omitempty"`
	SizeBytes int64     `json:"size_bytes"`
	SHA256    string    `json:"sha256,omitempty"`
}

type StoredFile struct {
	ID        uuid.UUID  `json:"id"`
	ThoughtID *uuid.UUID `json:"thought_id,omitempty"`
	ProjectID *uuid.UUID `json:"project_id,omitempty"`
	Name      string     `json:"name"`
	MediaType string     `json:"media_type"`
	Kind      string     `json:"kind"`
	Encoding  string     `json:"encoding"`
	SizeBytes int64      `json:"size_bytes"`
	SHA256    string     `json:"sha256"`
	Content   []byte     `json:"-"`
	CreatedAt time.Time  `json:"created_at"`
	UpdatedAt time.Time  `json:"updated_at"`
}

type StoredFileFilter struct {
	Limit     int
	ThoughtID *uuid.UUID
	ProjectID *uuid.UUID
	Kind      string
}

type Thought struct {
	ID              uuid.UUID       `json:"id"`
	Content         string          `json:"content"`
	Embedding       []float32       `json:"embedding,omitempty"`
	EmbeddingStatus string          `json:"embedding_status,omitempty"`
	Metadata        ThoughtMetadata `json:"metadata"`
	ProjectID       *uuid.UUID      `json:"project_id,omitempty"`
	ArchivedAt      *time.Time      `json:"archived_at,omitempty"`
	CreatedAt       time.Time       `json:"created_at"`
	UpdatedAt       time.Time       `json:"updated_at"`
}

type SearchResult struct {
	ID         uuid.UUID       `json:"id"`
	Content    string          `json:"content"`
	Metadata   ThoughtMetadata `json:"metadata"`
	Similarity float64         `json:"similarity"`
	CreatedAt  time.Time       `json:"created_at"`
}

type ListFilter struct {
	Limit           int
	Type            string
	Topic           string
	Person          string
	Days            int
	ProjectID       *uuid.UUID
	IncludeArchived bool
}

type ThoughtStats struct {
	TotalCount int            `json:"total_count"`
	TypeCounts map[string]int `json:"type_counts"`
	TopTopics  []KeyCount     `json:"top_topics"`
	TopPeople  []KeyCount     `json:"top_people"`
}

type KeyCount struct {
	Key   string `json:"key"`
	Count int    `json:"count"`
}
