-- ============================================
-- إنشاء جدول التقارير
-- AUTO TESTER - Reports Table
-- ============================================

CREATE TABLE IF NOT EXISTS reports (
    id INT PRIMARY KEY AUTO_INCREMENT,
    report_number VARCHAR(50) UNIQUE NOT NULL,
    inspection_id INT NOT NULL,
    
    -- بيانات التقرير (JSON)
    report_data JSON NOT NULL,
    
    -- ملف PDF
    pdf_path VARCHAR(255),
    
    -- الحالة
    status ENUM('draft', 'published', 'archived') DEFAULT 'published',
    
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    
    FOREIGN KEY (inspection_id) REFERENCES inspections(id) ON DELETE CASCADE,
    
    INDEX idx_inspection (inspection_id),
    INDEX idx_number (report_number),
    INDEX idx_created (created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;