import type { Song } from '../../features/song-select/types'

/** Metadata persisted to localStorage for a custom song. */
export type CustomSongMeta = {
  id: string
  title: string
  artist: string
  bpm: number
  difficulty: number
  duration: string
  genre: string
  color: string
  selectedDifficulty: string
  simplify: boolean
  /** File names stored in OPFS under /songs/{id}/ */
  audioFile: string
  chartFile: string
  bgFile: string
  bannerFile: string
}

export type CustomSongsState = {
  /** Runtime Song objects with blob URLs, ready for the carousel. */
  songs: Song[]
  /** Whether stored songs have been loaded from OPFS. */
  loaded: boolean
}

export type CustomSongsActions = {
  /** Load all stored songs from OPFS into runtime state. */
  loadStoredSongs: () => Promise<void>
  /** Add a song. If store=true, persist files to OPFS. */
  addSong: (
    meta: CustomSongMeta,
    files: Map<string, File>,
    store: boolean,
  ) => Promise<void>
  /** Remove a custom song by id. */
  removeSong: (id: string) => Promise<void>
}

export type CustomSongsStore = CustomSongsState & CustomSongsActions
