-- Update all 'cliente' to 'trader'
UPDATE "user" SET role = 'trader' WHERE role = 'cliente';

-- Update default value
ALTER TABLE "user" ALTER COLUMN "role" SET DEFAULT 'trader';

-- Create super user
INSERT INTO "user" (id, email, name, role, "emailVerified", "createdAt", "updatedAt")
VALUES (
  'super-' || gen_random_uuid(),
  'super@carntrack.com',
  'Super Admin',
  'super',
  TRUE,
  NOW(),
  NOW()
)
ON CONFLICT (email) DO NOTHING;

-- Get the super user ID and create account
INSERT INTO account (id, "accountId", "providerId", "userId", password)
SELECT
  gen_random_uuid(),
  'credential-' || u.id,
  'credential',
  u.id,
  '91ce3c3f68e0e8c1:8f8e8c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c9c'
FROM "user" u
WHERE u.email = 'super@carntrack.com' AND u.role = 'super'
ON CONFLICT DO NOTHING;

-- Show results
SELECT role, COUNT(*) as count FROM "user" GROUP BY role ORDER BY role;
