-- Hear For You - Database Schema
-- Create database
CREATE DATABASE IF NOT EXISTS `hear-for-you` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
USE `hear-for-you`;

-- Table: users
CREATE TABLE `users` (
  `id` INT AUTO_INCREMENT PRIMARY KEY,
  `name` VARCHAR(100) NOT NULL,
  `email` VARCHAR(100) NOT NULL UNIQUE,
  `password` VARCHAR(255) NOT NULL,
  `phone` VARCHAR(20) DEFAULT NULL,
  `role` ENUM('user', 'admin') DEFAULT 'user',
  `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  `updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table: services
CREATE TABLE `services` (
  `id` INT AUTO_INCREMENT PRIMARY KEY,
  `title` VARCHAR(100) NOT NULL,
  `description` TEXT,
  `price` INT NOT NULL,
  `duration` INT DEFAULT 60 COMMENT 'Duration in minutes',
  `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  `updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table: counselors
CREATE TABLE `counselors` (
  `id` INT AUTO_INCREMENT PRIMARY KEY,
  `name` VARCHAR(100) NOT NULL,
  `photo` VARCHAR(255) DEFAULT NULL,
  `expertise` VARCHAR(200) NOT NULL,
  `description` TEXT,
  `email` VARCHAR(100) DEFAULT NULL,
  `phone` VARCHAR(20) DEFAULT NULL,
  `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  `updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table: bookings
CREATE TABLE `bookings` (
  `id` INT AUTO_INCREMENT PRIMARY KEY,
  `user_id` INT NOT NULL,
  `service_id` INT NOT NULL,
  `counselor_id` INT NOT NULL,
  `booking_date` DATE NOT NULL,
  `booking_time` TIME NOT NULL,
  `status` ENUM('pending', 'approved', 'rejected', 'completed') DEFAULT 'pending',
  `meeting_link` VARCHAR(255) DEFAULT NULL,
  `notes` TEXT DEFAULT NULL,
  `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  `updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE CASCADE,
  FOREIGN KEY (`service_id`) REFERENCES `services`(`id`) ON DELETE CASCADE,
  FOREIGN KEY (`counselor_id`) REFERENCES `counselors`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table: payments
CREATE TABLE `payments` (
  `id` INT AUTO_INCREMENT PRIMARY KEY,
  `booking_id` INT NOT NULL,
  `amount` INT NOT NULL,
  `proof` VARCHAR(255) DEFAULT NULL,
  `status` ENUM('pending', 'verified', 'rejected') DEFAULT 'pending',
  `notes` TEXT DEFAULT NULL,
  `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  `updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  FOREIGN KEY (`booking_id`) REFERENCES `bookings`(`id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Table: password_resets
CREATE TABLE `password_resets` (
  `id` INT AUTO_INCREMENT PRIMARY KEY,
  `email` VARCHAR(100) NOT NULL,
  `token` VARCHAR(255) NOT NULL,
  `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  INDEX `idx_email` (`email`),
  INDEX `idx_token` (`token`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- Insert default admin user
-- Password: admin123 (hashed with bcrypt)
INSERT INTO `users` (`name`, `email`, `password`, `role`) VALUES
('Admin', 'admin@hearforyou.com', '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', 'admin');

-- Insert sample services
INSERT INTO `services` (`title`, `description`, `price`, `duration`) VALUES
('Konseling Individual', 'Sesi konseling pribadi dengan psikolog profesional untuk membantu mengatasi masalah personal Anda.', 150000, 60),
('Konseling Keluarga', 'Konseling untuk mengatasi konflik dan meningkatkan komunikasi dalam keluarga.', 250000, 90),
('Konseling Karir', 'Bimbingan profesional untuk pengembangan karir dan perencanaan masa depan Anda.', 200000, 60),
('Konseling Pasangan', 'Konseling untuk pasangan yang ingin memperbaiki hubungan dan komunikasi.', 300000, 90);

-- Insert sample counselors
INSERT INTO `counselors` (`name`, `photo`, `expertise`, `description`, `email`, `phone`) VALUES
('Dr. Sarah Johnson', 'counselor1.jpg', 'Psikologi Klinis, Terapi Kognitif', 'Psikolog klinis dengan pengalaman 10 tahun menangani anxiety, depresi, dan trauma.', 'sarah@hearforyou.com', '081234567890'),
('Dr. Michael Chen', 'counselor2.jpg', 'Konseling Keluarga & Pasangan', 'Ahli dalam terapi keluarga dan konseling pasangan dengan pendekatan holistik.', 'michael@hearforyou.com', '081234567891'),
('Dr. Amanda Smith', 'counselor3.jpg', 'Psikologi Perkembangan Anak', 'Spesialis psikologi anak dan remaja dengan 8 tahun pengalaman.', 'amanda@hearforyou.com', '081234567892'),
('Dr. David Lee', 'counselor4.jpg', 'Konseling Karir & Organisasi', 'Konsultan karir dan psikolog organisasi bersertifikat internasional.', 'david@hearforyou.com', '081234567893');
