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

slug: {
        type: DataTypes.TEXT,
      
      

      },

headline: {
        type: DataTypes.TEXT,
      
      

      },

thank_you_message: {
        type: DataTypes.TEXT,
      
      

      },

background_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"color",


"gradient",


"image",


"video"

        ],

      },

background_value: {
        type: DataTypes.TEXT,
      
      

      },

accent_color_hex: {
        type: DataTypes.TEXT,
      
      

      },

preset_amount_1: {
        type: DataTypes.INTEGER,
      
      

      },

preset_amount_2: {
        type: DataTypes.INTEGER,
      
      

      },

preset_amount_3: {
        type: DataTypes.INTEGER,
      
      

      },

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

      },

minimum_amount: {
        type: DataTypes.INTEGER,
      
      

      },

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

      },

tts_voice: {
        type: DataTypes.TEXT,
      
      

      },

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

      },

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

  tip_pages.associate = (db) => {


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






    db.tip_pages.hasMany(db.creator_profiles, {
      as: 'creator_profiles_tip_page',
      foreignKey: {
          name: 'tip_pageId',
      },
      constraints: false,
    });













    db.tip_pages.hasMany(db.tips, {
      as: 'tips_tip_page',
      foreignKey: {
          name: 'tip_pageId',
      },
      constraints: false,
    });



















//end loop



    db.tip_pages.belongsTo(db.creator_profiles, {
      as: 'creator',
      foreignKey: {
        name: 'creatorId',
      },
      constraints: false,
    });

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




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

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



  return tip_pages;
};


