/**
 * Form 16 – non-submitted dealer notification log.
 * Records each time an RE user sends a "submit Form 16" notification to a non-submitted dealer (per FY).
 */

import { QueryInterface, DataTypes } from 'sequelize';

export async function up(queryInterface: QueryInterface): Promise<void> {
  await queryInterface.createTable('form16_non_submitted_notifications', {
    id: {
      type: DataTypes.INTEGER,
      primaryKey: true,
      autoIncrement: true,
    },
    dealer_code: {
      type: DataTypes.STRING(50),
      allowNull: false,
    },
    financial_year: {
      type: DataTypes.STRING(20),
      allowNull: false,
    },
    notified_at: {
      type: DataTypes.DATE,
      allowNull: false,
      defaultValue: DataTypes.NOW,
    },
    notified_by: {
      type: DataTypes.UUID,
      allowNull: false,
      references: { model: 'users', key: 'user_id' },
    },
  });

  await queryInterface.addIndex('form16_non_submitted_notifications', ['dealer_code', 'financial_year'], {
    name: 'idx_form16_ns_notif_dealer_fy',
  });
  await queryInterface.addIndex('form16_non_submitted_notifications', ['notified_at'], {
    name: 'idx_form16_ns_notif_notified_at',
  });
}

export async function down(queryInterface: QueryInterface): Promise<void> {
  await queryInterface.dropTable('form16_non_submitted_notifications');
}
