-- Migration: Add cost-based pricing columns to jobs table
-- Task #6: Cost-based work fee pricing with BTC oracle

ALTER TABLE jobs
  ADD COLUMN IF NOT EXISTS estimated_cost_usd  REAL,
  ADD COLUMN IF NOT EXISTS margin_pct          REAL,
  ADD COLUMN IF NOT EXISTS btc_price_usd       REAL,
  ADD COLUMN IF NOT EXISTS actual_input_tokens INTEGER,
  ADD COLUMN IF NOT EXISTS actual_output_tokens INTEGER,
  ADD COLUMN IF NOT EXISTS actual_cost_usd     REAL;

COMMENT ON COLUMN jobs.estimated_cost_usd   IS 'Total estimated cost in USD at work invoice creation time (token + DO infra + margin)';
COMMENT ON COLUMN jobs.margin_pct           IS 'Originator margin percentage applied to this job';
COMMENT ON COLUMN jobs.btc_price_usd        IS 'BTC/USD price used to convert work fee to sats (from CoinGecko at invoice time)';
COMMENT ON COLUMN jobs.actual_input_tokens  IS 'Actual input token count reported by Anthropic after work execution';
COMMENT ON COLUMN jobs.actual_output_tokens IS 'Actual output token count reported by Anthropic after work execution';
COMMENT ON COLUMN jobs.actual_cost_usd      IS 'Actual raw Anthropic token cost (no infra amortisation, no margin) after work execution';
