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

name: {
        type: DataTypes.TEXT,
      
      

      },

layer_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"frame",


"text",


"image",


"button",


"group",


"vector"

        ],

      },

props: {
        type: DataTypes.TEXT,
      
      

      },

order: {
        type: DataTypes.INTEGER,
      
      

      },

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

      },

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

  layers.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.layers.belongsTo(db.pages, {
      as: 'page',
      foreignKey: {
        name: 'pageId',
      },
      constraints: false,
    });

    db.layers.belongsTo(db.layers, {
      as: 'parent',
      foreignKey: {
        name: 'parentId',
      },
      constraints: false,
    });

    db.layers.belongsTo(db.organizations, {
      as: 'organizations',
      foreignKey: {
        name: 'organizationsId',
      },
      constraints: false,
    });




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

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



  return layers;
};


