<?php
/**
 * Erstelle verification_documents Tabelle
 */

require_once '../config/database.php';

try {
    $db = new Database();
    $conn = $db->getConnection();
    
    $sql = "
    CREATE TABLE IF NOT EXISTS verification_documents (
        id INT AUTO_INCREMENT PRIMARY KEY,
        user_id INT NOT NULL,
        document_type ENUM('invoice', 'id_card', 'license', 'registration', 'insurance', 'other') DEFAULT 'invoice',
        file_name VARCHAR(255) NOT NULL,
        file_path VARCHAR(500) NOT NULL,
        file_size INT NOT NULL,
        mime_type VARCHAR(100) NOT NULL,
        upload_date TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
        review_status ENUM('pending', 'approved', 'rejected') DEFAULT 'pending',
        reviewed_by INT NULL,
        reviewed_at TIMESTAMP NULL,
        review_notes TEXT NULL,
        rejection_reason TEXT NULL,
        created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
        updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
        FOREIGN KEY (user_id) REFERENCES users(id) ON DELETE CASCADE,
        FOREIGN KEY (reviewed_by) REFERENCES admin_users(id) ON DELETE SET NULL,
        INDEX idx_user_id (user_id),
        INDEX idx_review_status (review_status),
        INDEX idx_upload_date (upload_date)
    )";
    
    $conn->exec($sql);
    echo "Tabelle verification_documents erfolgreich erstellt oder bereits vorhanden.\n";
    
} catch (Exception $e) {
    echo "Fehler beim Erstellen der Tabelle: " . $e->getMessage() . "\n";
}
?>
