-- Add listpickup.current_state for workflow WITHOUT renaming legacy `status`.
-- Safe for environments where legacy still reads/writes `listpickup.status`.

ALTER TABLE `listpickup`
  ADD COLUMN `current_state` VARCHAR(255) DEFAULT NULL;

UPDATE `listpickup`
SET `current_state` = CASE
  WHEN `status` IN ('Abierta', 'ABIERTA', 'OPEN', 'open') THEN 'DRAFT'
  WHEN `status` IN ('Cerrada', 'CERRADA', 'CLOSED', 'closed') THEN 'COMPLETED'
  WHEN `status` IN ('DRAFT', 'READY', 'IN_PROGRESS', 'COMPLETED', 'CANCELLED') THEN `status`
  ELSE 'DRAFT'
END
WHERE `current_state` IS NULL;

ALTER TABLE `listpickup`
  MODIFY COLUMN `current_state` VARCHAR(255) NOT NULL;
