import type { UserPublic as User } from './user'

export type ChoreFrequency = 'one_time' | 'daily' | 'weekly' | 'monthly' | 'custom'
export type ChoreType = 'personal' | 'group'
export type ChoreHistoryEventType = 'created' | 'updated' | 'deleted' | 'completed' | 'reopened' | 'assigned' | 'unassigned' | 'reassigned' | 'schedule_generated' | 'due_date_changed' | 'details_changed'

export interface Chore {
  id: number
  group_id?: number | null
  name: string
  description?: string | null
  created_by_id: number
  frequency: ChoreFrequency
  custom_interval_days?: number | null
  next_due_date: string
  last_completed_at?: string
  created_at: string
  updated_at: string
  type: ChoreType
  creator?: User
  assignments: ChoreAssignment[]
  history?: ChoreHistory[]
}

export interface ChoreCreate extends Omit<Chore, 'id'> { }

export interface ChoreUpdate extends Partial<ChoreCreate> { }

// Chore Assignment Types
export interface ChoreAssignment {
  id: number
  chore_id: number
  assigned_to_user_id: number
  assigned_by_id: number
  due_date: string
  is_complete: boolean
  completed_at?: string
  created_at: string
  updated_at: string
  chore?: Chore
  assigned_user?: User
  history?: ChoreAssignmentHistory[]
}

export interface ChoreAssignmentCreate {
  chore_id: number
  assigned_to_user_id: number
  due_date: string
}

export interface ChoreAssignmentUpdate {
  is_complete?: boolean
  due_date?: string
  assigned_to_user_id?: number
}

export interface ChoreHistory {
  id: number
  event_type: ChoreHistoryEventType
  event_data?: Record<string, any>
  changed_by_user?: User
  timestamp: string
}

export interface ChoreAssignmentHistory {
  id: number
  event_type: ChoreHistoryEventType
  event_data?: Record<string, any>
  changed_by_user?: User
  timestamp: string
}

export interface ChoreWithCompletion extends Chore {
  current_assignment_id: number | null;
  is_completed: boolean;
  completed_at: string | null;
  updating: boolean;
  assigned_user_name?: string;
  completed_by_name?: string;
  assigned_to_user_id?: number | null;
  parent_chore_id?: number | null;
  child_chores?: ChoreWithCompletion[];
  subtext?: string;
}
