const config = require('../../config');
const providers = config.providers;
const crypto = require('crypto');
const bcrypt = require('bcrypt');
const moment = require('moment');

module.exports = function(sequelize, DataTypes) {
  const shared_dashboard_posts = sequelize.define(
    'shared_dashboard_posts',
    {
      id: {
        type: DataTypes.UUID,
        defaultValue: DataTypes.UUIDV4,
        primaryKey: true,
      },

post_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"update",


"question",


"note",


"photo",


"document"

        ],

      },

title_text: {
        type: DataTypes.TEXT,
      
      

      },

content: {
        type: DataTypes.TEXT,
      
      

      },

posted_at: {
        type: DataTypes.DATE,
      
      

      },

visibility: {
        type: DataTypes.ENUM,
      
      

        values: [

"family_only",


"care_team",


"all_authorized"

        ],

      },

      importHash: {
        type: DataTypes.STRING(255),
        allowNull: true,
        unique: true,
      },
    },
    {
      timestamps: true,
      paranoid: true,
      freezeTableName: true,
    },
  );

  shared_dashboard_posts.associate = (db) => {


/// loop through entities and it's fields, and if ref === current e[name] and create relation has many on parent entity





























//end loop



    db.shared_dashboard_posts.belongsTo(db.patients, {
      as: 'patient',
      foreignKey: {
        name: 'patientId',
      },
      constraints: false,
    });

    db.shared_dashboard_posts.belongsTo(db.users, {
      as: 'author_user',
      foreignKey: {
        name: 'author_userId',
      },
      constraints: false,
    });

    db.shared_dashboard_posts.belongsTo(db.accounts, {
      as: 'accounts',
      foreignKey: {
        name: 'accountsId',
      },
      constraints: false,
    });



    db.shared_dashboard_posts.hasMany(db.file, {
      as: 'photos',
      foreignKey: 'belongsToId',
      constraints: false,
      scope: {
        belongsTo: db.shared_dashboard_posts.getTableName(),
        belongsToColumn: 'photos',
      },
    });

    db.shared_dashboard_posts.hasMany(db.file, {
      as: 'attachments',
      foreignKey: 'belongsToId',
      constraints: false,
      scope: {
        belongsTo: db.shared_dashboard_posts.getTableName(),
        belongsToColumn: 'attachments',
      },
    });


    db.shared_dashboard_posts.belongsTo(db.users, {
      as: 'createdBy',
    });

    db.shared_dashboard_posts.belongsTo(db.users, {
      as: 'updatedBy',
    });
  };



  return shared_dashboard_posts;
};


