ALTER TABLE maintenance_jobs
    MODIFY COLUMN workflow_stage ENUM(
        'Complaint Logged',
        'Maintenance Review',
        'Work Order Raised',
        'RFQ Sent',
        'Quote Submitted',
        'Quote Vetted',
        'Job Order Approved',
        'Workshop In Progress',
        'Inspection',
        'Internal Control',
        'Closed',
        'Requisition Raised',
        'Payment Made',
        'Payment Not Made',
        'Suspended',
        'Cancelled'
    ) NOT NULL DEFAULT 'Complaint Logged';

ALTER TABLE maintenance_jobs
    MODIFY COLUMN status ENUM(
        'Pending',
        'Approved',
        'Rejected',
        'In Progress',
        'Completed',
        'Suspended',
        'Cancelled',
        'Closed',
        'Paid',
        'Not Paid',
        'Job Order Created',
        'Requisition Raised',
        'Payment Made',
        'Payment Not Made'
    ) NULL DEFAULT 'Pending';

UPDATE maintenance_jobs
SET workflow_stage = 'Requisition Raised',
    status = CASE WHEN status IS NULL OR status = '' OR status = 'Pending' THEN 'Requisition Raised' ELSE status END
WHERE TRIM(requisition_status) = 'Raised';

UPDATE maintenance_jobs
SET workflow_stage = 'Requisition Raised',
    status = 'Approved'
WHERE TRIM(requisition_status) = 'Approved';

UPDATE maintenance_jobs
SET workflow_stage = 'Payment Made',
    status = 'Payment Made'
WHERE TRIM(requisition_status) IN ('Paid', 'Payment Made');

UPDATE maintenance_jobs
SET workflow_stage = 'Payment Not Made',
    status = 'Not Paid'
WHERE TRIM(requisition_status) = 'Not Paid';
