ALTER TABLE "user" ADD COLUMN IF NOT EXISTS "pin_hash" varchar(255);
ALTER TABLE "user" ADD COLUMN IF NOT EXISTS "employee_number" varchar(20) UNIQUE;

-- Auto-assign employee numbers to existing users
DO $$ DECLARE r RECORD; num INT := 1001;
BEGIN
  FOR r IN (SELECT id FROM "user" WHERE employee_number IS NULL ORDER BY created_at) LOOP
    UPDATE "user" SET employee_number = num::text WHERE id = r.id;
    num := num + 1;
  END LOOP;
END $$;

-- Seed POS config
INSERT INTO "app_config" ("key", "value", "description") VALUES
  ('pos_lock_timeout', '15', 'POS auto-lock timeout in minutes (0 to disable)'),
  ('receipt_header', '', 'Text shown below logo on receipts'),
  ('receipt_footer', '', 'Thank you message at bottom of receipt'),
  ('receipt_return_policy', '', 'Return policy text on receipt (blank to hide)'),
  ('receipt_social', '', 'Website or social media shown on receipt')
ON CONFLICT ("key") DO NOTHING;
