import type { QueryInterface } from 'sequelize';
import { SAFETY_QUIZ_CONTENT_TYPE } from '@/shared/constants/content-catalog';

export default {
  up: async (queryInterface: QueryInterface) => {
    await queryInterface.sequelize.query(
      `
        UPDATE content_catalog
        SET active = false, "deletedAt" = NOW(), "updatedAt" = NOW()
        WHERE content_type = :contentType
          AND "deletedAt" IS NULL
          AND ("schoolId" IS NOT NULL OR "campusId" IS NOT NULL OR "classId" IS NOT NULL)
      `,
      { replacements: { contentType: SAFETY_QUIZ_CONTENT_TYPE } },
    );
  },

  down: async () => {
    // Do not recreate formerly duplicated school/campus quiz rows on rollback.
  },
};
