<?php
require_once 'controllers/ConversationNotesController.php';
$conversationNotesController = new ConversationNotesController();

// Save conversation note (create or update)
if ($method === 'POST' && $uri === '/conversation-notes') {
    $data = json_decode(file_get_contents('php://input'), true);
    $response = $conversationNotesController->saveNote($data);
    echo $response;
    exit;
}

// Get notes by call ID
if ($method === 'GET' && $uri === '/conversation-notes-call') {
    $callId = $_GET['id'] ?? null;
    $response = $conversationNotesController->getNotesByCall($callId);
    echo $response;
    exit;
}

// Get notes by follow-up ID
if ($method === 'GET' && $uri === '/conversation-notes-followup') {
    $followUpId = $_GET['id'] ?? null;
    $response = $conversationNotesController->getNotesByFollowUp($followUpId);
    echo $response;
    exit;
}

// Get notes by invoice ID
if ($method === 'GET' && $uri === '/conversation-notes-invoice') {
    $invoiceId = $_GET['id'] ?? null;
    $response = $conversationNotesController->getNotesByInvoice($invoiceId);
    echo $response;
    exit;
}

// Delete note
if ($method === 'DELETE' && $uri === '/conversation-notes') {
    $noteId = $_GET['id'] ?? null;
    $response = $conversationNotesController->deleteNote($noteId);
    echo $response;
    exit;
}

// Get conversation notes statistics
if ($method === 'GET' && $uri === '/conversation-notes-stats') {
    $filters = [
        'ipo_id' => $_GET['ipo_id'] ?? null,
        'date_from' => $_GET['date_from'] ?? null,
        'date_to' => $_GET['date_to'] ?? null
    ];
    $response = $conversationNotesController->getNoteStats($filters);
    echo $response;
    exit;
}
