-- =====================================================================
-- Migration: Daily Buy Order Limits by Min Buy Range
-- Date: 2026-08-23
-- Description: Adds DailyBuyOrderLimit table for super admin to configure
--              how many buy orders a user can place per day based on their
--              dynamic minimum buy amount range.
-- =====================================================================

CREATE TABLE IF NOT EXISTS `DailyBuyOrderLimit` (
  `id`              VARCHAR(191)    NOT NULL PRIMARY KEY,
  `created_at`      DATETIME(3)     NOT NULL DEFAULT CURRENT_TIMESTAMP(3),
  `updated_at`      DATETIME(3)     NOT NULL DEFAULT CURRENT_TIMESTAMP(3) ON UPDATE CURRENT_TIMESTAMP(3),
  `min_buy_amount`  DECIMAL(30,10)  NOT NULL,
  `max_buy_amount`  DECIMAL(30,10)  NULL,
  `max_daily_orders` INT           NOT NULL,
  `is_active`       BOOLEAN         NOT NULL DEFAULT TRUE,
  `sort_order`      INT            NOT NULL DEFAULT 0,
  `metadata`        JSON            NULL,
  INDEX `idx_daily_limit_active_order` (`is_active`, `sort_order`),
  INDEX `idx_daily_limit_min_buy` (`min_buy_amount`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;
