'use strict';
const {
  Model
} = require('sequelize');
module.exports = (sequelize, DataTypes) => {
  class RegisterAssignment extends Model {
    /**
     * Helper method for defining associations.
     * This method is not a part of Sequelize lifecycle.
     * The `models/index` file will call this method automatically.
     */
    static associate(models) {
      RegisterAssignment.belongsTo(models.Register, {
        foreignKey: 'registerId',
        as: 'register'
      });
      RegisterAssignment.belongsTo(models.User, {
        foreignKey: 'userId',
        as: 'user'
      });
      RegisterAssignment.belongsTo(models.User, {
        foreignKey: 'assignedBy',
        as: 'assignedByUser'
      });
    }
  }
  RegisterAssignment.init({
    registerId: DataTypes.INTEGER,
    userId: DataTypes.INTEGER,
    assignedBy: DataTypes.INTEGER,
    assignedAt: DataTypes.DATE,
    unassignedAt: DataTypes.DATE,
    isActive: DataTypes.BOOLEAN,
    isPrimary: DataTypes.BOOLEAN
  }, {
    sequelize,
    modelName: 'RegisterAssignment',
  });
  return RegisterAssignment;
};