-- migration_multi_login.sql
-- Add role + permissions to admins table

ALTER TABLE admins
  ADD COLUMN IF NOT EXISTS full_name  VARCHAR(150) DEFAULT NULL,
  ADD COLUMN IF NOT EXISTS role       ENUM('superadmin','admin','support') DEFAULT 'support',
  ADD COLUMN IF NOT EXISTS permissions JSON DEFAULT NULL,
  ADD COLUMN IF NOT EXISTS is_active  TINYINT(1) DEFAULT 1;

-- Set existing admin as superadmin
UPDATE admins SET role = 'superadmin', is_active = 1 WHERE username = 'admin';

-- Add acted_by to orders (who approved/rejected)
ALTER TABLE orders
  ADD COLUMN IF NOT EXISTS acted_by_admin_id   INT DEFAULT NULL,
  ADD COLUMN IF NOT EXISTS acted_by_username   VARCHAR(100) DEFAULT NULL;
