const { supabase } = require('../config/supabase');

// POST: voice_ask - AI voice assistant
exports.ask = async (req, res) => {
  const { clientId, user_name, token, question, deployment_id } = req.body;

  try {
    // TODO: Integrate with OpenAI/Claude for voice AI
    // For now, return a placeholder response

    // Get deployment context
    let context = null;
    if (deployment_id) {
      const { data } = await supabase
        .from('deployments')
        .select('*')
        .eq('deployment_id', deployment_id)
        .single();
      context = data;
    }

    // Placeholder AI response
    const response = {
      success: true,
      question,
      answer: `I received your question: "${question}". Voice AI integration is pending.`,
      deployment_context: context ? {
        id: context.deployment_id,
        persons: context.persons,
        time_zone: context.time_zone_s
      } : null,
      timestamp: new Date().toISOString()
    };

    return res.json(response);
  } catch (error) {
    return res.status(500).json({ error: error.message });
  }
};
