import { MigrationInterface, QueryRunner } from 'typeorm';

/**
 * 移除 ai_messages 上已废弃的 like/dislike 反馈字段。
 * 反馈功能已从前端和后端删除，历史列一并清理。
 */
export class DropAiMessageFeedback1784920000000 implements MigrationInterface {
  async up(queryRunner: QueryRunner): Promise<void> {
    for (const column of ['feedback', 'feedback_reason']) {
      if (await queryRunner.hasColumn('ai_messages', column)) {
        await queryRunner.dropColumn('ai_messages', column);
      }
    }
  }

  async down(queryRunner: QueryRunner): Promise<void> {
    if (!(await queryRunner.hasColumn('ai_messages', 'feedback'))) {
      await queryRunner.query(
        'ALTER TABLE ai_messages ADD COLUMN feedback varchar(20) NULL',
      );
    }
    if (!(await queryRunner.hasColumn('ai_messages', 'feedback_reason'))) {
      await queryRunner.query(
        'ALTER TABLE ai_messages ADD COLUMN feedback_reason varchar(500) NULL',
      );
    }
  }
}
