-- Create table for scheduled profit distribution
CREATE TABLE IF NOT EXISTS `profit_schedules` (
  `id` INT UNSIGNED AUTO_INCREMENT PRIMARY KEY,
  `user_id` INT UNSIGNED NOT NULL,
  `currency` VARCHAR(10) NOT NULL,
  `amount` DECIMAL(15, 2) NOT NULL,
  `frequency` ENUM('daily', 'weekly', 'monthly') NOT NULL,
  `next_distribution` DATETIME NOT NULL,
  `last_distribution` DATETIME NULL,
  `status` ENUM('active', 'paused', 'completed') DEFAULT 'active',
  `total_distributed` DECIMAL(15, 2) DEFAULT 0.00,
  `distribution_count` INT DEFAULT 0,
  `created_by` INT NULL,
  `created_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
  `updated_at` TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
  `note` TEXT NULL,
  FOREIGN KEY (`user_id`) REFERENCES `users`(`id`) ON DELETE CASCADE,
  INDEX `idx_next_distribution` (`next_distribution`, `status`),
  INDEX `idx_user_currency` (`user_id`, `currency`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
