-- v4.0.2：活动图模板（底图 + 方形码栏 + 文案）

ALTER TABLE `common_resource`
  MODIFY COLUMN `biz_type` ENUM(
    'COVER',
    'ENV',
    'CONTRACT',
    'CAROUSEL',
    'DETAIL',
    'AVATAR',
    'QRCODE',
    'SIGN_PHOTO',
    'VIDEO',
    'REDEEM_PENDING_PHOTO',
    'ACTIVITY_POSTER'
  ) NOT NULL;

CREATE TABLE IF NOT EXISTS `activity_poster` (
  `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT,
  `title` VARCHAR(128) NOT NULL,
  `copy_text` TEXT NOT NULL,
  `image_url` VARCHAR(512) NOT NULL,
  `qr_x_pct` DECIMAL(5,2) NOT NULL,
  `qr_y_pct` DECIMAL(5,2) NOT NULL,
  `qr_size_pct` DECIMAL(5,2) NOT NULL,
  `sort_order` INT NOT NULL DEFAULT 0,
  `status` VARCHAR(16) NOT NULL DEFAULT 'ACTIVE',
  `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_activity_poster_status_sort` (`status`, `sort_order`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='HQ 活动图模板';

INSERT IGNORE INTO `hq_role_permission` (`admin_role`, `permission_key`)
SELECT 'OPS', 'activity_posters'
FROM DUAL
WHERE EXISTS (SELECT 1 FROM `hq_role_permission` WHERE `admin_role` = 'OPS');
