module.exports = function(sequelize, DataTypes) {
  const prep_briefs = sequelize.define(
    "prep_briefs",
    {
      id: { type: DataTypes.UUID, defaultValue: DataTypes.UUIDV4, primaryKey: true },
      next_session_at: { type: DataTypes.DATE },
      previous_summary: { type: DataTypes.TEXT },
      open_commitments: { type: DataTypes.TEXT },
      suggested_questions: { type: DataTypes.TEXT },
      sensitive_topics: { type: DataTypes.TEXT },
      client_reflection: { type: DataTypes.TEXT },
      client_reflection_at: { type: DataTypes.DATE },
      status: { type: DataTypes.ENUM("draft", "ready", "archived"), defaultValue: "ready" },
      importHash: { type: DataTypes.STRING(255), allowNull: true, unique: true },
    },
    {
      timestamps: true,
      paranoid: true,
      freezeTableName: true,
    },
  );

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

  return prep_briefs;
};
