-- Plan credits balance (tokens); resets on monthly billing run per company tier.
ALTER TABLE "companies" ADD COLUMN IF NOT EXISTS "license_credits_remaining" bigint DEFAULT 5000000 NOT NULL;

-- Backfill tier defaults for existing companies
UPDATE "companies" SET "license_credits_remaining" = 5000000 WHERE "package" = 'starter';
UPDATE "companies" SET "license_credits_remaining" = 10000000 WHERE "package" = 'professional';
UPDATE "companies" SET "license_credits_remaining" = 15000000 WHERE "package" = 'enterprise';

-- Upfront cost approval snapshot per conversion (DB table remains `projects`)
ALTER TABLE "projects" ADD COLUMN IF NOT EXISTS "approved_estimated_tokens" integer;
ALTER TABLE "projects" ADD COLUMN IF NOT EXISTS "approved_gross_eur_cents" integer;
ALTER TABLE "projects" ADD COLUMN IF NOT EXISTS "approved_net_eur_cents" integer;
ALTER TABLE "projects" ADD COLUMN IF NOT EXISTS "approved_credits_tokens_applied" integer;
ALTER TABLE "projects" ADD COLUMN IF NOT EXISTS "cost_approved_at" timestamp;
