module.exports = (sequelize, DataTypes) => {
  const CorrectiveActionReportPermanent = sequelize.define('CorrectiveActionReportPermanent', {
    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_permanent',
    underscored: true,
    timestamps: true,
    createdAt: 'created_at',
    updatedAt: 'updated_at',
    indexes: [{ fields: ['report_id'] }]
  });

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

  return CorrectiveActionReportPermanent;
};
