-- Migration: Add return_condition to return_items
-- Date: 2026-03-30
-- Records per-line condition: intact (restocked) vs damaged (not restocked for sale).
-- Idempotent: safe to run more than once.

SET @dbname = DATABASE();
SET @exists = (
  SELECT COUNT(*) FROM INFORMATION_SCHEMA.COLUMNS
  WHERE TABLE_SCHEMA = @dbname AND TABLE_NAME = 'return_items' AND COLUMN_NAME = 'return_condition'
);
SET @sql = IF(@exists = 0,
  'ALTER TABLE `return_items` ADD COLUMN `return_condition` ENUM(''intact'',''damaged'') DEFAULT NULL COMMENT ''Returned unit condition for audit'' AFTER `is_restocked`',
  'SELECT 1'
);
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
