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 content_assets = sequelize.define(
    'content_assets',
    {
      id: {
        type: DataTypes.UUID,
        defaultValue: DataTypes.UUIDV4,
        primaryKey: true,
      },

asset_title: {
        type: DataTypes.TEXT,
      
      

      },

asset_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"article",


"pdf",


"image",


"video",


"link",


"template"

        ],

      },

body: {
        type: DataTypes.TEXT,
      
      

      },

asset_url: {
        type: DataTypes.TEXT,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"draft",


"published",


"archived"

        ],

      },

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

  content_assets.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.content_assets.belongsTo(db.organizations, {
      as: 'organization',
      foreignKey: {
        name: 'organizationId',
      },
      constraints: false,
    });



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


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

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



  return content_assets;
};


