// Database Types for Music App

export interface User {
  id: string
  email: string
  password_hash?: string
  name: string
  avatar_url: string | null
  role: "user" | "artist" | "admin"
  subscription_type: "free" | "premium" | "family" | "student" | "hifi"
  subscription_expires_at: Date | null
  is_verified: boolean
  is_active: boolean
  language: string
  country: string | null
  created_at: Date
  updated_at: Date
  last_login_at: Date | null
}

export interface Artist {
  id: string
  user_id: string | null
  name: string
  bio: string | null
  avatar_url: string | null
  cover_url: string | null
  is_verified: boolean
  monthly_listeners: number
  total_followers: number
  total_streams: number
  country: string | null
  genres: string[]
  social_links: Record<string, string>
  created_at: Date
  updated_at: Date
}

export interface Album {
  id: string
  title: string
  artist_id: string
  cover_url: string | null
  release_date: Date | null
  album_type: "album" | "single" | "ep" | "compilation"
  total_tracks: number
  duration_ms: number
  label: string | null
  copyright: string | null
  is_explicit: boolean
  total_streams: number
  status: "draft" | "pending" | "published" | "archived"
  created_at: Date
  updated_at: Date
  // Joined fields
  artist?: Artist
}

export interface Track {
  id: string
  title: string
  artist_id: string
  album_id: string | null
  duration_ms: number
  audio_url: string
  preview_url: string | null
  cover_url: string | null
  track_number: number | null
  disc_number: number
  is_explicit: boolean
  is_playable: boolean
  lyrics: string | null
  lyrics_synced: { time: number; text: string }[] | null
  bpm: number | null
  key: string | null
  isrc: string | null
  total_streams: number
  total_saves: number
  status: "draft" | "pending" | "published" | "archived" | "rejected"
  rejection_reason: string | null
  created_at: Date
  updated_at: Date
  // Joined fields
  artist?: Artist
  album?: Album
}

export interface Playlist {
  id: string
  name: string
  description: string | null
  cover_url: string | null
  user_id: string | null
  is_public: boolean
  is_collaborative: boolean
  is_editorial: boolean
  total_tracks: number
  total_duration_ms: number
  total_followers: number
  created_at: Date
  updated_at: Date
  // Joined fields
  user?: User
  tracks?: Track[]
}

export interface Genre {
  id: string
  name: string
  slug: string
  description: string | null
  color: string | null
  icon_url: string | null
  is_featured: boolean
  track_count: number
  created_at: Date
}

export interface Category {
  id: string
  name: string
  slug: string
  description: string | null
  icon_url: string | null
  color: string | null
  parent_id: string | null
  sort_order: number
  is_visible: boolean
  created_at: Date
}

export interface SubscriptionPlan {
  id: string
  name: string
  slug: string
  description: string | null
  price_monthly: number
  price_yearly: number | null
  features: string[]
  max_devices: number
  offline_listening: boolean
  ad_free: boolean
  hifi_quality: boolean
  is_active: boolean
  created_at: Date
}

export interface UserSubscription {
  id: string
  user_id: string
  plan_id: string
  status: "active" | "canceled" | "expired" | "past_due"
  current_period_start: Date
  current_period_end: Date
  cancel_at_period_end: boolean
  payment_method: string | null
  created_at: Date
  updated_at: Date
  // Joined fields
  plan?: SubscriptionPlan
  user?: User
}

export interface ListeningHistory {
  id: string
  user_id: string
  track_id: string
  played_at: Date
  duration_played_ms: number | null
  context_type: string | null
  context_id: string | null
  // Joined fields
  track?: Track
}

export interface Notification {
  id: string
  user_id: string | null
  title: string
  message: string
  type: "info" | "success" | "warning" | "error" | "promo"
  action_url: string | null
  is_read: boolean
  is_broadcast: boolean
  created_at: Date
}

export interface SupportTicket {
  id: string
  user_id: string | null
  subject: string
  category: string | null
  priority: "low" | "medium" | "high" | "urgent"
  status: "open" | "in_progress" | "waiting" | "resolved" | "closed"
  assigned_to: string | null
  created_at: Date
  updated_at: Date
  resolved_at: Date | null
  // Joined fields
  user?: User
  messages?: TicketMessage[]
}

export interface TicketMessage {
  id: string
  ticket_id: string
  user_id: string | null
  message: string
  is_staff_reply: boolean
  attachments: string[]
  created_at: Date
}

export interface ContentReport {
  id: string
  reporter_id: string | null
  content_type: "track" | "album" | "playlist" | "user" | "comment"
  content_id: string
  reason: string
  description: string | null
  status: "pending" | "reviewing" | "resolved" | "dismissed"
  resolution: string | null
  resolved_by: string | null
  created_at: Date
  resolved_at: Date | null
}

export interface ArtistEarnings {
  id: string
  artist_id: string
  track_id: string | null
  period_start: Date
  period_end: Date
  streams: number
  earnings_amount: number
  status: "pending" | "approved" | "paid"
  paid_at: Date | null
  created_at: Date
}

export interface Promotion {
  id: string
  title: string
  description: string | null
  image_url: string | null
  action_url: string | null
  target_type: string | null
  position: string
  start_date: Date | null
  end_date: Date | null
  is_active: boolean
  impressions: number
  clicks: number
  created_at: Date
}
