-- Create Database
CREATE DATABASE IF NOT EXISTS numerology_master;
USE numerology_master;

-- Admin Table
CREATE TABLE IF NOT EXISTS admin (
  id INT AUTO_INCREMENT PRIMARY KEY,
  name VARCHAR(100) NOT NULL,
  email VARCHAR(100) UNIQUE NOT NULL,
  password VARCHAR(255) NOT NULL,
  role ENUM('superadmin','admin') DEFAULT 'admin',
  refresh_token TEXT NULL,
  created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  INDEX idx_email (email),
  INDEX idx_role (role)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Users Table (existing table)

-- Insert demo admin (password: admin123 hashed with bcrypt)
-- Hash generated for "admin123"
INSERT INTO admin (name, email, password, role) 
VALUES ('Super Admin', 'admin@numerology.com', '$2b$10$i8UjJoZnFVCilJzOdcBLkehS7FUaAeq5sA2AbevLaPMbj5nFNYpTu', 'superadmin')
ON DUPLICATE KEY UPDATE password='$2b$10$i8UjJoZnFVCilJzOdcBLkehS7FUaAeq5sA2AbevLaPMbj5nFNYpTu';

