import api from './api'

// Mock responses for demo purposes since we don't have real backend/keys yet
const mockResponses = {
  'chatgpt': "I'm ChatGPT. I can help you with code, writing, and more.",
  'gemini': "I'm Gemini. I can reason across text, code, images, and video.",
  'nana-banana': "I'm Nana Banana! Let's make something fun and creative.",
  'kling': "I'm Kling. I specialize in high-quality video generation."
}

export const aiService = {
  // Send message to specific AI model
  async sendMessage(modelId, message, history = []) {
    // In a real app, this would be:
    // return api.post(`/ai/${modelId}/chat`, { message, history })
    
    // Simulating API call
    return new Promise((resolve) => {
      setTimeout(() => {
        const response = mockResponses[modelId] || "I'm an AI assistant.";
        resolve({
          id: Date.now(),
          role: 'assistant',
          content: `${response} (Response to: "${message.substring(0, 20)}...")`,
          timestamp: new Date()
        })
      }, 1000 + Math.random() * 1000)
    })
  },

  // Get available models
  async getModels() {
    // return api.get('/models')
    return [
      { id: 'chatgpt', name: 'ChatGPT', provider: 'OpenAI' },
      { id: 'gemini', name: 'Gemini', provider: 'Google' },
      { id: 'nana-banana', name: 'Nana Banana', provider: 'Custom' },
      { id: 'kling', name: 'Kling', provider: 'Kling AI' }
    ]
  },

  // Run generation task
  async runGeneration(payload) {
    const response = await api.post('/generations/_run', payload)
    return response.data
  },

  // Get generation status
  async getGenerationStatus(id) {
    const response = await api.get(`/generations/${id}`)
    return response.data
  },

  // Get generations history
  async getGenerations(limit, offset, characterId) {
    const params = { limit, offset }
    if (characterId) params.character_id = characterId
    const response = await api.get('/generations', { params })
    return response.data
  },

  // Improve prompt using assistant
  async improvePrompt(prompt, linkedAssets = []) {
    const response = await api.post('/generations/prompt-assistant', { 
      prompt,
      linked_assets: linkedAssets
    })
    return response.data
  }
}
