package types

import (
	"time"

	"github.com/google/uuid"
)

// Household Knowledge

type HouseholdItem struct {
	ID        uuid.UUID      `json:"id"`
	Name      string         `json:"name"`
	Category  string         `json:"category,omitempty"`
	Location  string         `json:"location,omitempty"`
	Details   map[string]any `json:"details"`
	Notes     string         `json:"notes,omitempty"`
	CreatedAt time.Time      `json:"created_at"`
	UpdatedAt time.Time      `json:"updated_at"`
}

type HouseholdVendor struct {
	ID          uuid.UUID  `json:"id"`
	Name        string     `json:"name"`
	ServiceType string     `json:"service_type,omitempty"`
	Phone       string     `json:"phone,omitempty"`
	Email       string     `json:"email,omitempty"`
	Website     string     `json:"website,omitempty"`
	Notes       string     `json:"notes,omitempty"`
	Rating      *int       `json:"rating,omitempty"`
	LastUsed    *time.Time `json:"last_used,omitempty"`
	CreatedAt   time.Time  `json:"created_at"`
}

// Home Maintenance

type MaintenanceTask struct {
	ID            uuid.UUID  `json:"id"`
	Name          string     `json:"name"`
	Category      string     `json:"category,omitempty"`
	FrequencyDays *int       `json:"frequency_days,omitempty"`
	LastCompleted *time.Time `json:"last_completed,omitempty"`
	NextDue       *time.Time `json:"next_due,omitempty"`
	Priority      string     `json:"priority"`
	Notes         string     `json:"notes,omitempty"`
	CreatedAt     time.Time  `json:"created_at"`
	UpdatedAt     time.Time  `json:"updated_at"`
}

type MaintenanceLog struct {
	ID          uuid.UUID `json:"id"`
	TaskID      uuid.UUID `json:"task_id"`
	CompletedAt time.Time `json:"completed_at"`
	PerformedBy string    `json:"performed_by,omitempty"`
	Cost        *float64  `json:"cost,omitempty"`
	Notes       string    `json:"notes,omitempty"`
	NextAction  string    `json:"next_action,omitempty"`
}

type MaintenanceLogWithTask struct {
	MaintenanceLog
	TaskName     string `json:"task_name"`
	TaskCategory string `json:"task_category,omitempty"`
}

// Family Calendar

type FamilyMember struct {
	ID           uuid.UUID  `json:"id"`
	Name         string     `json:"name"`
	Relationship string     `json:"relationship,omitempty"`
	BirthDate    *time.Time `json:"birth_date,omitempty"`
	Notes        string     `json:"notes,omitempty"`
	CreatedAt    time.Time  `json:"created_at"`
}

type Activity struct {
	ID             uuid.UUID  `json:"id"`
	FamilyMemberID *uuid.UUID `json:"family_member_id,omitempty"`
	MemberName     string     `json:"member_name,omitempty"`
	Title          string     `json:"title"`
	ActivityType   string     `json:"activity_type,omitempty"`
	DayOfWeek      string     `json:"day_of_week,omitempty"`
	StartTime      string     `json:"start_time,omitempty"`
	EndTime        string     `json:"end_time,omitempty"`
	StartDate      *time.Time `json:"start_date,omitempty"`
	EndDate        *time.Time `json:"end_date,omitempty"`
	Location       string     `json:"location,omitempty"`
	Notes          string     `json:"notes,omitempty"`
	CreatedAt      time.Time  `json:"created_at"`
}

type ImportantDate struct {
	ID                 uuid.UUID  `json:"id"`
	FamilyMemberID     *uuid.UUID `json:"family_member_id,omitempty"`
	MemberName         string     `json:"member_name,omitempty"`
	Title              string     `json:"title"`
	DateValue          time.Time  `json:"date_value"`
	RecurringYearly    bool       `json:"recurring_yearly"`
	ReminderDaysBefore int        `json:"reminder_days_before"`
	Notes              string     `json:"notes,omitempty"`
	CreatedAt          time.Time  `json:"created_at"`
}

// Meal Planning

type Ingredient struct {
	Name     string `json:"name"`
	Quantity string `json:"quantity,omitempty"`
	Unit     string `json:"unit,omitempty"`
}

type Recipe struct {
	ID              uuid.UUID    `json:"id"`
	Name            string       `json:"name"`
	Cuisine         string       `json:"cuisine,omitempty"`
	PrepTimeMinutes *int         `json:"prep_time_minutes,omitempty"`
	CookTimeMinutes *int         `json:"cook_time_minutes,omitempty"`
	Servings        *int         `json:"servings,omitempty"`
	Ingredients     []Ingredient `json:"ingredients"`
	Instructions    []string     `json:"instructions"`
	Tags            []string     `json:"tags"`
	Rating          *int         `json:"rating,omitempty"`
	Notes           string       `json:"notes,omitempty"`
	CreatedAt       time.Time    `json:"created_at"`
	UpdatedAt       time.Time    `json:"updated_at"`
}

type MealPlanEntry struct {
	ID         uuid.UUID  `json:"id"`
	WeekStart  time.Time  `json:"week_start"`
	DayOfWeek  string     `json:"day_of_week"`
	MealType   string     `json:"meal_type"`
	RecipeID   *uuid.UUID `json:"recipe_id,omitempty"`
	RecipeName string     `json:"recipe_name,omitempty"`
	CustomMeal string     `json:"custom_meal,omitempty"`
	Servings   *int       `json:"servings,omitempty"`
	Notes      string     `json:"notes,omitempty"`
	CreatedAt  time.Time  `json:"created_at"`
}

type MealPlanInput struct {
	DayOfWeek  string     `json:"day_of_week" jsonschema:"day of week (monday-sunday)"`
	MealType   string     `json:"meal_type" jsonschema:"one of: breakfast, lunch, dinner, snack"`
	RecipeID   *uuid.UUID `json:"recipe_id,omitempty" jsonschema:"optional recipe id"`
	CustomMeal string     `json:"custom_meal,omitempty" jsonschema:"optional free-text meal description when no recipe"`
	Servings   *int       `json:"servings,omitempty"`
	Notes      string     `json:"notes,omitempty"`
}

type ShoppingItem struct {
	Name      string     `json:"name"`
	Quantity  string     `json:"quantity,omitempty"`
	Unit      string     `json:"unit,omitempty"`
	Purchased bool       `json:"purchased"`
	RecipeID  *uuid.UUID `json:"recipe_id,omitempty"`
}

type ShoppingList struct {
	ID        uuid.UUID      `json:"id"`
	WeekStart time.Time      `json:"week_start"`
	Items     []ShoppingItem `json:"items"`
	Notes     string         `json:"notes,omitempty"`
	CreatedAt time.Time      `json:"created_at"`
	UpdatedAt time.Time      `json:"updated_at"`
}

// Professional CRM

type ProfessionalContact struct {
	ID            uuid.UUID  `json:"id"`
	Name          string     `json:"name"`
	Company       string     `json:"company,omitempty"`
	Title         string     `json:"title,omitempty"`
	Email         string     `json:"email,omitempty"`
	Phone         string     `json:"phone,omitempty"`
	LinkedInURL   string     `json:"linkedin_url,omitempty"`
	HowWeMet      string     `json:"how_we_met,omitempty"`
	Tags          []string   `json:"tags"`
	Notes         string     `json:"notes,omitempty"`
	LastContacted *time.Time `json:"last_contacted,omitempty"`
	FollowUpDate  *time.Time `json:"follow_up_date,omitempty"`
	CreatedAt     time.Time  `json:"created_at"`
	UpdatedAt     time.Time  `json:"updated_at"`
}

type ContactInteraction struct {
	ID              uuid.UUID `json:"id"`
	ContactID       uuid.UUID `json:"contact_id"`
	InteractionType string    `json:"interaction_type"`
	OccurredAt      time.Time `json:"occurred_at"`
	Summary         string    `json:"summary"`
	FollowUpNeeded  bool      `json:"follow_up_needed"`
	FollowUpNotes   string    `json:"follow_up_notes,omitempty"`
	CreatedAt       time.Time `json:"created_at"`
}

type Opportunity struct {
	ID                uuid.UUID  `json:"id"`
	ContactID         *uuid.UUID `json:"contact_id,omitempty"`
	Title             string     `json:"title"`
	Description       string     `json:"description,omitempty"`
	Stage             string     `json:"stage"`
	Value             *float64   `json:"value,omitempty"`
	ExpectedCloseDate *time.Time `json:"expected_close_date,omitempty"`
	Notes             string     `json:"notes,omitempty"`
	CreatedAt         time.Time  `json:"created_at"`
	UpdatedAt         time.Time  `json:"updated_at"`
}

type ContactHistory struct {
	Contact       ProfessionalContact  `json:"contact"`
	Interactions  []ContactInteraction `json:"interactions"`
	Opportunities []Opportunity        `json:"opportunities"`
}

// Agent Skills & Guardrails

type AgentSkill struct {
	ID          int64     `json:"id"`
	GUID        uuid.UUID `json:"guid"`
	Name        string    `json:"name"`
	Description string    `json:"description,omitempty"`
	Content     string    `json:"content"`
	Tags        []string  `json:"tags"`
	CreatedAt   time.Time `json:"created_at"`
	UpdatedAt   time.Time `json:"updated_at"`
}

type AgentGuardrail struct {
	ID          int64     `json:"id"`
	GUID        uuid.UUID `json:"guid"`
	Name        string    `json:"name"`
	Description string    `json:"description,omitempty"`
	Content     string    `json:"content"`
	Severity    string    `json:"severity"`
	Tags        []string  `json:"tags"`
	CreatedAt   time.Time `json:"created_at"`
	UpdatedAt   time.Time `json:"updated_at"`
}

// Chat Histories

type ChatMessage struct {
	Role    string `json:"role"`
	Content string `json:"content"`
}

type ChatHistory struct {
	ID        int64          `json:"id"`
	GUID      uuid.UUID      `json:"guid"`
	SessionID string         `json:"session_id"`
	Title     string         `json:"title,omitempty"`
	Channel   string         `json:"channel,omitempty"`
	AgentID   string         `json:"agent_id,omitempty"`
	ProjectID *int64         `json:"project_id,omitempty"`
	Messages  []ChatMessage  `json:"messages"`
	Summary   string         `json:"summary,omitempty"`
	Metadata  map[string]any `json:"metadata"`
	CreatedAt time.Time      `json:"created_at"`
	UpdatedAt time.Time      `json:"updated_at"`
}
