CREATE TABLE IF NOT EXISTS `prize_grant_activities` (
  `id` BIGINT NOT NULL AUTO_INCREMENT,
  `reason` VARCHAR(255) NOT NULL COMMENT '发奖原因',
  `status` VARCHAR(16) NOT NULL DEFAULT 'inactive' COMMENT '状态:active/inactive',
  `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),
  PRIMARY KEY (`id`),
  KEY `idx_pga_status_id` (`status`, `id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='奖品发放活动';

CREATE TABLE IF NOT EXISTS `prize_grant_activity_rewards` (
  `id` BIGINT NOT NULL AUTO_INCREMENT,
  `activity_id` BIGINT NOT NULL COMMENT '活动ID',
  `reward_type` VARCHAR(32) NOT NULL COMMENT '奖品类型:product/item_card/coupon',
  `reward_ref_id` BIGINT NOT NULL COMMENT '奖品资源ID',
  `quantity_per_claim` INT NOT NULL DEFAULT 1 COMMENT '每次领取数量',
  `sort` INT NOT NULL DEFAULT 0 COMMENT '排序',
  `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),
  PRIMARY KEY (`id`),
  KEY `idx_pgar_activity` (`activity_id`, `sort`, `id`),
  KEY `idx_pgar_reward` (`reward_type`, `reward_ref_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='奖品发放活动奖品';

CREATE TABLE IF NOT EXISTS `prize_grant_activity_user_records` (
  `id` BIGINT NOT NULL AUTO_INCREMENT,
  `activity_id` BIGINT NOT NULL COMMENT '活动ID',
  `user_id` BIGINT NOT NULL COMMENT '用户ID',
  `status` VARCHAR(16) NOT NULL COMMENT '状态:claimed/processed',
  `claimed_at` DATETIME(3) NULL DEFAULT NULL COMMENT '领取时间',
  `processed_at` DATETIME(3) NULL DEFAULT NULL COMMENT '处理时间',
  `operator_admin_id` BIGINT NOT NULL DEFAULT 0 COMMENT '操作管理员ID',
  `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),
  PRIMARY KEY (`id`),
  UNIQUE KEY `uk_pgaur_activity_user` (`activity_id`, `user_id`),
  KEY `idx_pgaur_activity_status` (`activity_id`, `status`, `updated_at`),
  KEY `idx_pgaur_user_status` (`user_id`, `status`, `updated_at`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci COMMENT='奖品发放活动用户记录';
