// API 공통 타입 정의

export interface ApiResponse<T> {
  success: boolean;
  data?: T;
  error?: string;
  message?: string;
  status?: number;
}

export interface ApiError {
  status: number;
  message: string;
  details?: unknown;
}

// VIBE 관련 타입
export interface VibeLoginRequest {
  id: string;        // 이메일
  password: string;
}

// VIBE Artist 정보
export interface VibeArtist {
  artist_id: number;
  artist_name: string;
  image_url?: string;
}

// VIBE Album 정보
export interface VibeAlbum {
  album_id: number;
  album_title: string;
  release_date?: string;
  image_url?: string;
}

// VIBE Track 정보
export interface VibeTrack {
  track_id: number;
  track_title: string;
  artists: VibeArtist[];
  album: VibeAlbum;
  play_time: string;
  has_lyric: boolean;
  is_streaming: boolean;
}

// VIBE Playlist 정보
export interface VibePlaylist {
  playlist_id: string;
  playlist_name: string;
  description?: string;
  track_count: number;
  image_url?: string;
  created_at?: string;
  updated_at?: string;
  tracks?: VibeTrack[];
}

// VIBE 플레이리스트 응답
export interface VibePlaylistsResponse {
  success: boolean;
  message: string;
  playlists: VibePlaylist[];
  session_id?: string;
}

export interface VibeUrlRequest {
  url: string;
}

// VIBE 트랙 목록 요청
export interface VibeTracksRequest {
  playlist_ids: string[];
}

// VIBE 트랙 목록 응답
export interface VibeTracksResponse {
  success: boolean;
  message: string;
  tracks: VibeTrack[];
}

// 기타 스트리밍 서비스 타입 (확장 가능)
export interface StreamingServicePlaylist {
  id: string | number;
  name: string;
  trackCount: number;
  selected?: boolean;
  imageUrl?: string;
  description?: string;
}

export interface PlaylistTransferRequest {
  sourceService: string;
  targetService: string;
  playlistIds: string[];
}

export interface PlaylistTransferResponse {
  success: boolean;
  transferredCount: number;
  failedCount: number;
  details?: string[];
}

// Spotify 관련 타입
export interface SpotifyAuthResponse {
  access_token: string;
  token_type: string;
  expires_in: number;
  refresh_token?: string;
  scope: string;
}

export interface SpotifyPlaylist {
  id: string;
  name: string;
  description: string | null;
  public: boolean;
  collaborative: boolean;
  tracks: {
    total: number;
  };
  images: Array<{
    url: string;
    height: number | null;
    width: number | null;
  }>;
  owner: {
    id: string;
    display_name: string;
  };
}

export interface SpotifyPlaylistsResponse {
  items: SpotifyPlaylist[];
  total: number;
  limit: number;
  offset: number;
}

export interface SpotifyTrack {
  id: string;
  name: string;
  artists: Array<{
    id: string;
    name: string;
  }>;
  album: {
    id: string;
    name: string;
    images: Array<{
      url: string;
      height: number | null;
      width: number | null;
    }>;
  };
  duration_ms: number;
  uri: string;
}

// Spotify OAuth 콜백 요청 타입
export interface SpotifyAuthCallbackRequest {
  access_token: string;
  token_type: string;
  expires_in: number;
  refresh_token?: string;
  scope: string;
}

// Spotify OAuth 콜백 응답 타입
export interface SpotifyAuthCallbackResponse {
  success: boolean;
  message: string;
  session_id: string;
  expires_in: number;
}

// Spotify 플레이리스트 목록 조회 응답 (백엔드 API)
export interface SpotifyBackendPlaylistsResponse {
  success: boolean;
  message?: string;
  playlists: SpotifyPlaylist[];
}

// Spotify 트랙 추가 요청 타입
export interface SpotifyAddTracksRequest {
  playlist_id?: string | null;
  playlist_name?: string;
  playlist_description?: string;
  is_public?: boolean;
  tracks: SpotifyTrackInfo[];
}

export interface SpotifyTrackInfo {
  track_title: string;
  artist_name: string;
  album_title?: string;
}

// Spotify 트랙 추가 응답 타입
export interface SpotifyAddTracksResponse {
  success: boolean;
  message?: string;
  playlist_id?: string;
  added_count?: number;
  failed_count?: number;
}
