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

media_kind: {
        type: DataTypes.ENUM,
      
      

        values: [

"image",


"video"

        ],

      },

media_role: {
        type: DataTypes.ENUM,
      
      

        values: [

"before",


"after",


"process",


"final",


"detail",


"other"

        ],

      },

caption_ar: {
        type: DataTypes.TEXT,
      
      

      },

sort_order: {
        type: DataTypes.INTEGER,
      
      

      },

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

      },

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

  project_media.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.project_media.belongsTo(db.projects, {
      as: 'project',
      foreignKey: {
        name: 'projectId',
      },
      constraints: false,
    });



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

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


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

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



  return project_media;
};


