-- ALSO Cloud Billing workflow columns
-- Supports matching/validation timestamps and approval linkage to local order drafts.

ALTER TABLE also_import_lines
ADD COLUMN IF NOT EXISTS matching_checked_at TIMESTAMP,
ADD COLUMN IF NOT EXISTS validation_checked_at TIMESTAMP,
ADD COLUMN IF NOT EXISTS approved_at TIMESTAMP,
ADD COLUMN IF NOT EXISTS approved_by_user_id INTEGER REFERENCES users(user_id) ON DELETE SET NULL,
ADD COLUMN IF NOT EXISTS order_draft_id INTEGER REFERENCES ordre_drafts(id) ON DELETE SET NULL,
ADD COLUMN IF NOT EXISTS invoiced_at TIMESTAMP;

CREATE INDEX IF NOT EXISTS idx_also_import_lines_order_draft ON also_import_lines(order_draft_id);
CREATE INDEX IF NOT EXISTS idx_also_import_lines_approved_at ON also_import_lines(approved_at DESC);
