module.exports = (sequelize, DataTypes) => {
  const CorrectiveActionReportInterim = sequelize.define('CorrectiveActionReportInterim', {
    id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
    report_id: {
      type: DataTypes.INTEGER,
      allowNull: false,
      references: { model: 'CorrectiveActionReport', key: 'id' },
      onDelete: 'CASCADE'
    },
    line_no: { type: DataTypes.INTEGER, allowNull: false },
    responsibility: { type: DataTypes.STRING(300), allowNull: true },
    target: { type: DataTypes.STRING(300), allowNull: true }
  }, {
    tableName: 'corrective_action_report_interim',
    underscored: true,
    timestamps: true,
    createdAt: 'created_at',
    updatedAt: 'updated_at',
    indexes: [{ fields: ['report_id'] }]
  });

  CorrectiveActionReportInterim.associate = function(models) {
    CorrectiveActionReportInterim.belongsTo(models.CorrectiveActionReport, { foreignKey: 'report_id', as: 'report' });
  };

  return CorrectiveActionReportInterim;
};
