export interface Task {
  id: string
  name: string
  points: number
  is_good: boolean
  image_id: string | null
  image_url?: string | null // optional, for resolved URLs
}
export const TASK_FIELDS = ['id', 'name', 'points', 'is_good', 'image_id'] as const

export interface Child {
  id: string
  name: string
  age: number
  tasks: string[]
  rewards: string[]
  points: number
  image_id: string | null
  image_url?: string | null // optional, for resolved URLs
}
export const CHILD_FIELDS = ['id', 'name', 'age', 'tasks', 'rewards', 'points', 'image_id'] as const

export interface Reward {
  id: string
  name: string
  cost: number
  points_needed: number
  image_id: string | null
  image_url?: string | null // optional, for resolved URLs
}
export const REWARD_FIELDS = ['id', 'name', 'cost', 'points_needed', 'image_id'] as const

export interface RewardStatus {
  id: string
  name: string
  points_needed: number
  cost: number
  redeeming: boolean
  image_id: string | null
  image_url?: string | null // optional, for resolved URLs
}
export const REWARD_STATUS_FIELDS = [
  'id',
  'name',
  'points_needed',
  'cost',
  'redeeming',
  'image_id',
] as const

export interface PendingReward {
  id: string
  child_id: string
  child_name: string
  child_image_id: string | null
  child_image_url?: string | null // optional, for resolved URLs
  reward_id: string
  reward_name: string
  reward_image_id: string | null
  reward_image_url?: string | null // optional, for resolved URLs
}
export const PENDING_REWARD_FIELDS = [
  'id',
  'child_id',
  'child_name',
  'child_image_id',
  'reward_id',
  'reward_name',
  'reward_image_id',
] as const

export interface Event {
  type: string
  payload:
    | ChildModifiedEventPayload
    | ChildTaskTriggeredEventPayload
    | ChildRewardTriggeredEventPayload
    | ChildRewardRequestEventPayload
    | ChildTasksSetEventPayload
    | ChildRewardsSetEventPayload
    | TaskModifiedEventPayload
    | RewardModifiedEventPayload
}

export interface ChildModifiedEventPayload {
  child_id: string
  operation: 'ADD' | 'DELETE' | 'EDIT'
}

export interface ChildTaskTriggeredEventPayload {
  task_id: string
  child_id: string
  points: number
}

export interface ChildRewardTriggeredEventPayload {
  task_id: string
  child_id: string
  points: number
}

export interface ChildRewardRequestEventPayload {
  child_id: string
  reward_id: string
  operation: 'GRANTED' | 'CREATED' | 'CANCELLED'
}

export interface ChildTasksSetEventPayload {
  child_id: string
  task_ids: string[]
}

export interface ChildRewardsSetEventPayload {
  child_id: string
  reward_ids: string[]
}
export interface TaskModifiedEventPayload {
  task_id: string
  operation: 'ADD' | 'DELETE' | 'EDIT'
}
export interface RewardModifiedEventPayload {
  reward_id: string
  operation: 'ADD' | 'DELETE' | 'EDIT'
}
