-- ============================================
-- إنشاء جدول الفحوصات
-- AUTO TESTER - Inspections Table
-- ============================================

CREATE TABLE IF NOT EXISTS inspections (
    id INT PRIMARY KEY AUTO_INCREMENT,
    inspection_number VARCHAR(50) UNIQUE NOT NULL,
    
    -- المرتبطون
    client_id INT NOT NULL,
    vehicle_id INT NOT NULL,
    inspector_id INT NOT NULL,
    supervisor_id INT,
    
    -- نوع الفحص
    inspection_type ENUM(
        'comprehensive', 'dyno', 'brakes', 'engine', 
        'electrical', 'external', 'computer', 'apps'
    ) NOT NULL,
    
    -- المنطقة
    area VARCHAR(100),
    
    -- النتائج
    engine_efficiency DECIMAL(5,2),
    overall_rating DECIMAL(5,2),
    
    -- ملاحظات
    notes TEXT,
    
    -- الصور
    front_image TEXT,
    left_image TEXT,
    rear_image TEXT,
    right_image TEXT,
    interior_front TEXT,
    interior_rear TEXT,
    
    -- صور المدخل
    photo_position TEXT,
    photo_performance TEXT,
    photo_engine TEXT,
    photo_odometer TEXT,
    
    -- الحالة
    status ENUM('pending', 'in-progress', 'completed', 'cancelled') DEFAULT 'pending',
    
    -- التواريخ
    inspection_date DATETIME,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    completed_at TIMESTAMP NULL,
    
    INDEX idx_client (client_id),
    INDEX idx_inspector (inspector_id),
    INDEX idx_status (status),
    INDEX idx_type (inspection_type),
    INDEX idx_date (inspection_date)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;