CREATE TABLE inventory_items (
    id INT AUTO_INCREMENT PRIMARY KEY,
    inventory_id INT NOT NULL,
    asset_id INT NOT NULL,
    soll_status ENUM('aktiv', 'inaktiv', 'ausgemustert') NOT NULL,
    ist_status ENUM('gefunden', 'nicht_gefunden', 'defekt', 'verschoben') NOT NULL,
    checked_at TIMESTAMP NULL,
    checked_by INT,
    bemerkung TEXT,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    FOREIGN KEY (inventory_id) REFERENCES inventories(id) ON DELETE CASCADE,
    FOREIGN KEY (asset_id) REFERENCES assets(id) ON DELETE CASCADE,
    FOREIGN KEY (checked_by) REFERENCES users(id) ON DELETE SET NULL,
    INDEX idx_inventory_id (inventory_id),
    INDEX idx_asset_id (asset_id),
    INDEX idx_checked_by (checked_by),
    INDEX idx_ist_status (ist_status),
    UNIQUE KEY unique_inventory_asset (inventory_id, asset_id)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
