module.exports = function(sequelize, DataTypes) {
  const vorta_social_comments = sequelize.define(
    'vorta_social_comments',
    {
      id: {
        type: DataTypes.UUID,
        defaultValue: DataTypes.UUIDV4,
        primaryKey: true,
      },
      post_id: {
        type: DataTypes.UUID,
        allowNull: false,
      },
      user: {
        type: DataTypes.STRING(255),
        allowNull: false,
      },
      comment: {
        type: DataTypes.TEXT,
        allowNull: false,
      },
      parent_id: {
        type: DataTypes.STRING(255),
        allowNull: false,
        defaultValue: '0',
      },
      created_at: {
        type: DataTypes.DATE,
        allowNull: false,
        defaultValue: DataTypes.NOW,
      },
      importHash: {
        type: DataTypes.STRING(255),
        allowNull: true,
        unique: true,
      },
    },
    {
      timestamps: false,
      freezeTableName: true,
    },
  );

  vorta_social_comments.associate = (db) => {
    db.vorta_social_comments.belongsTo(db.vorta_social_posts, {
      as: 'post',
      foreignKey: {
        name: 'post_id',
      },
      constraints: false,
    });

    db.vorta_social_comments.belongsTo(db.users, {
      as: 'account',
      foreignKey: {
        name: 'userId',
      },
      constraints: false,
    });

    db.vorta_social_comments.belongsTo(db.organizations, {
      as: 'organizations',
      foreignKey: {
        name: 'organizationsId',
      },
      constraints: false,
    });
  };

  return vorta_social_comments;
};
