module.exports = function(sequelize, DataTypes) {
  const action_items = sequelize.define(
    "action_items",
    {
      id: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, primaryKey: true },
      title: { type: DataTypes.TEXT },
      due_at: { type: DataTypes.DATE },
      status: { type: DataTypes.ENUM("not_started", "in_progress", "done"), defaultValue: "not_started" },
      notes: { type: DataTypes.TEXT },
      importHash: { type: DataTypes.STRING(255), allowNull: true, unique: true },
    },
    {
      timestamps: true,
      paranoid: true,
      freezeTableName: true,
    },
  );

  action_items.associate = (db) => {
    db.action_items.belongsTo(db.clients, { as: "client", foreignKey: { name: "clientId" }, constraints: false });
    db.action_items.belongsTo(db.sessions, { as: "session", foreignKey: { name: "sessionId" }, constraints: false });
    db.action_items.belongsTo(db.users, { as: "createdBy", constraints: false });
    db.action_items.belongsTo(db.users, { as: "updatedBy", constraints: false });
  };

  return action_items;
};
