-- Drop order_sequences table
DROP TABLE IF EXISTS order_sequences;

-- Remove boolean flags and related fields from orders
ALTER TABLE orders DROP COLUMN IF EXISTS refunded_by;
ALTER TABLE orders DROP COLUMN IF EXISTS refunded_at;
ALTER TABLE orders DROP COLUMN IF EXISTS refund_reason;
ALTER TABLE orders DROP COLUMN IF EXISTS voided_by;
ALTER TABLE orders DROP COLUMN IF EXISTS voided_at;
ALTER TABLE orders DROP COLUMN IF EXISTS void_reason;
ALTER TABLE orders DROP COLUMN IF EXISTS is_refund;
ALTER TABLE orders DROP COLUMN IF EXISTS is_void;

-- Remove refund_amount field from orders
ALTER TABLE orders DROP COLUMN IF EXISTS refund_amount;

-- Revert payment status constraints
ALTER TABLE orders DROP CONSTRAINT orders_payment_status_check;
ALTER TABLE orders ADD CONSTRAINT orders_payment_status_check CHECK (payment_status IN ('pending', 'completed', 'failed', 'refunded'));

-- Revert order status constraints
ALTER TABLE orders DROP CONSTRAINT orders_status_check;
ALTER TABLE orders ADD CONSTRAINT orders_status_check CHECK (status IN ('pending', 'preparing', 'ready', 'completed', 'cancelled'));

-- Remove cost fields from order_items table
ALTER TABLE order_items DROP COLUMN IF EXISTS total_cost;
ALTER TABLE order_items DROP COLUMN IF EXISTS unit_cost;

-- Remove cost fields from orders table
ALTER TABLE orders DROP COLUMN IF EXISTS total_cost;
