import { User, Stream, StreamPlatform, ChatMessage, StudioScene, ApiResponse } from './types'

const mockUser: User = { id: '1', name: 'César Mendívil', email: 'cesar@avanzacast.com', avatar: '', role: 'admin', createdAt: new Date().toISOString(), isActive: true, plan: 'pro' }

const mockPlatforms: StreamPlatform[] = [
  { id: '1', name: 'youtube', displayName: 'YouTube', isConnected: true, accountName: 'AvanzaCast Channel', isLive: false, viewerCount: 0 },
  { id: '2', name: 'facebook', displayName: 'Facebook Live', isConnected: true, accountName: 'AvanzaCast Page', isLive: false, viewerCount: 0 }
]

const mockStreams: Stream[] = [
  { id: '1', title: 'Tutorial: Cómo usar AvanzaCast', description: 'Aprende a crear transmisiones', status: 'ended', userId: '1', startedAt: new Date().toISOString(), platforms: mockPlatforms, viewerCount: 0, maxViewers: 245, chatEnabled: true, isPrivate: false, tags: [] }
]

const delay = (ms = 300) => new Promise(resolve => setTimeout(resolve, ms))

export class MockAPI {
  static async login(email: string, password: string): Promise<ApiResponse<User>> {
    await delay()
    if (email === mockUser.email && password === 'password') return { success: true, data: mockUser }
    return { success: false, error: 'Credenciales inválidas' }
  }
  static async register(userData: Partial<User>): Promise<ApiResponse<User>> { await delay(); return { success: true, data: { ...mockUser, id: Date.now().toString(), name: userData.name || '', email: userData.email || '' } } }
  static async getStreams(): Promise<ApiResponse<Stream[]>>{ await delay(); return { success: true, data: mockStreams } }
  static async getPlatforms(): Promise<ApiResponse<StreamPlatform[]>>{ await delay(); return { success: true, data: mockPlatforms } }
  static async getScenes(): Promise<ApiResponse<StudioScene[]>>{ await delay(); return { success: true, data: [] } }
  static async getChatMessages(streamId: string): Promise<ApiResponse<ChatMessage[]>>{ await delay(); return { success: true, data: [] } }
}
