/** Coach–learner chat (technical-plan 4.11). */

export type ChatRole = "learner" | "coach" | "admin"

export interface ChatCoachDto {
  id: number | null
  name: string | null
  slug: string | null
  avatar: string | null
}

/** GET /v1/chats */
export interface ChatListItemDto {
  id: number
  coach: ChatCoachDto
  last_message: { preview: string; mine: boolean; role: ChatRole; at: string | null } | null
  unread_count: number
  read_only: boolean
}

/** GET /v1/chats/{id}, POST /v1/chats */
export interface ChatHeaderDto {
  id: number
  coach: ChatCoachDto
  course: { id: number; title: string } | null
  /** Every course the learner has from this coach. */
  courses: { id: number; title: string }[]
  locked: boolean
  read_only: boolean
  last_read_id: number
  other_last_read_id: number
}

export interface ChatMessageDto {
  id: number
  mine: boolean
  role: ChatRole
  sender_name: string
  /** "hidden": removed by Rangook; "deleted": by its sender. */
  state: "normal" | "deleted" | "hidden"
  body: string | null
  placeholder: string | null
  image: string | null
  reply_to: { id: number; role: ChatRole; sender_name: string; preview: string } | null
  edited: boolean
  editable: boolean
  /** Own messages: read by the other side (✓✓). */
  read: boolean | null
  created_at: string
}

/** GET /v1/chats/{id}/messages */
export interface ChatMessagesDto {
  messages: ChatMessageDto[]
  has_more: boolean
  other_last_read_id: number
  read_only: boolean
}
