import type { Song } from '@/models/song';
import type { AudioEffectValue, AudioQualityValue, PlayMode } from '../../types';
import type { ClimaxMark, PlaybackNotice } from './types';

export const createPlayerState = () => ({
  isPlaying: false,
  isLyricViewOpen: false,
  volume: 0.8,
  currentTime: 0,
  duration: 0,
  playbackRate: 1,
  playMode: 'list' as PlayMode,
  equalizerGains: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] as number[],
  currentTrackId: null as string | null,
  currentSourceQueueId: null as string | null,
  isLoading: false,
  lastError: '' as string | null,
  currentPlaylist: null as Song[] | null,
  currentAudioUrl: '' as string,
  currentResolvedAudioQuality: null as AudioQualityValue | null,
  currentResolvedAudioEffect: 'none' as AudioEffectValue,
  audioEffect: 'none' as AudioEffectValue,
  recentSeekIgnoreEnd: false,
  settingsWatcherRegistered: false,
  isDraggingProgress: false,
  pendingSettingRefresh: false,
  climaxMarks: [] as ClimaxMark[],
  outputDeviceWatcherRegistered: false,
  outputDeviceRefreshTimer: null as number | null,
  appliedOutputDeviceId: 'default' as string,
  _lastAppliedExclusive: false,
  currentAudioQualityOverride: null as AudioQualityValue | null,
  playbackRequestSeq: 0,
  climaxRequestSeq: 0,
  currentTrackSnapshot: null as Song | null,
  historyUploadCommitted: false,
  historyUploadTrackId: null as string | null,
  historyUploadPlayCount: 0,
  historyPlayCountMap: {} as Record<string, number>,
  autoNextTimer: null as number | null,
  autoNextAttempts: 0,
  autoNextSourceTrackId: null as string | null,
  playbackNotice: null as PlaybackNotice | null,
  shuffleQueue: null as number[] | null,
  shuffleQueueLength: 0,
  shufflePlayed: new Set<number>(),
  seekTargetTime: null as number | null,
  seekTimestamp: 0,
  isResuming: false,
});

export type PlayerState = ReturnType<typeof createPlayerState>;
