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

title: {
        type: DataTypes.TEXT,
      
      

      },

asset_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"image",


"document",


"video_link"

        ],

      },

video_url: {
        type: DataTypes.TEXT,
      
      

      },

alt_text: {
        type: DataTypes.TEXT,
      
      

      },

caption: {
        type: DataTypes.TEXT,
      
      

      },

is_public: {
        type: DataTypes.BOOLEAN,
      
        allowNull: false,
        defaultValue: false,
      
      

      },

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

  media_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.media_assets.belongsTo(db.services, {
      as: 'service',
      foreignKey: {
        name: 'serviceId',
      },
      constraints: false,
    });

    db.media_assets.belongsTo(db.projects, {
      as: 'project',
      foreignKey: {
        name: 'projectId',
      },
      constraints: false,
    });



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

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


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

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



  return media_assets;
};


