package models

import (
	"time"
)

func (Todo) TableName() string {
	return "todos"
}

type Todo struct {
	BaseModel
	UserID      ULID   `json:"userId" db:"user_id" gorm:"not null"`
	Title       string `json:"title" db:"title" gorm:"not null"`
	Description string `json:"description" db:"description"`
	Color       string `json:"color" db:"color" gorm:"default:'#3B82F6'"` // Default blue color
	IsActive    bool   `json:"isActive" db:"is_active" gorm:"default:true"`

	// Relationships
	User        User             `json:"user" gorm:"foreignKey:UserID"`
	Completions []TodoCompletion `json:"completions" gorm:"foreignKey:TodoID"`
}

func (TodoCompletion) TableName() string {
	return "todo_completions"
}

type TodoCompletion struct {
	BaseModel
	TodoID      ULID      `json:"todoId" db:"todo_id" gorm:"not null"`
	UserID      ULID      `json:"userId" db:"user_id" gorm:"not null"`
	CompletedAt time.Time `json:"completedAt" db:"completed_at" gorm:"not null"`
	Description string    `json:"description" db:"description"` // User's notes about how they completed it

	// Relationships
	Todo Todo `json:"todo" gorm:"foreignKey:TodoID"`
	User User `json:"user" gorm:"foreignKey:UserID"`
}

// TodoWithStats represents a todo with completion statistics
type TodoWithStats struct {
	Todo
	CurrentStreak    int        `json:"currentStreak"`
	LongestStreak    int        `json:"longestStreak"`
	TotalCompletions int        `json:"totalCompletions"`
	LastCompletedAt  *time.Time `json:"lastCompletedAt"`
	CompletedToday   bool       `json:"completedToday"`
}

// DailyTodoSummary represents todos for a specific day
type DailyTodoSummary struct {
	Date           time.Time       `json:"date"`
	Todos          []TodoWithStats `json:"todos"`
	CompletedCount int             `json:"completedCount"`
	TotalCount     int             `json:"totalCount"`
}
