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

name: {
        type: DataTypes.TEXT,
      
      

      },

mode: {
        type: DataTypes.ENUM,
      
      

        values: [

"text",


"image"

        ],

      },

default_text_template: {
        type: DataTypes.TEXT,
      
      

      },

opacity: {
        type: DataTypes.DECIMAL,
      
      

      },

position: {
        type: DataTypes.ENUM,
      
      

        values: [

"top_left",


"top_right",


"bottom_left",


"bottom_right",


"center"

        ],

      },

scale: {
        type: DataTypes.DECIMAL,
      
      

      },

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

      },

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

  watermark_profiles.associate = (db) => {


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



























    db.watermark_profiles.hasMany(db.download_jobs, {
      as: 'download_jobs_watermark_profile',
      foreignKey: {
          name: 'watermark_profileId',
      },
      constraints: false,
    });















//end loop



    db.watermark_profiles.belongsTo(db.organizations, {
      as: 'organization',
      foreignKey: {
        name: 'organizationId',
      },
      constraints: false,
    });



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


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

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



  return watermark_profiles;
};


