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

handle: {
        type: DataTypes.TEXT,
      
      

      },

creator_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"streamer",


"youtuber",


"vtuber",


"music_creator",


"artist",


"developer",


"adult_creator",


"other"

        ],

      },

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

      },

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

      },

slogan: {
        type: DataTypes.TEXT,
      
      

      },

about: {
        type: DataTypes.TEXT,
      
      

      },

business_email: {
        type: DataTypes.TEXT,
      
      

      },

support_email: {
        type: DataTypes.TEXT,
      
      

      },

preferred_language: {
        type: DataTypes.TEXT,
      
      

      },

category_tags: {
        type: DataTypes.TEXT,
      
      

      },

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

  creator_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.creator_profiles.hasMany(db.follows, {
      as: 'follows_followed_creator',
      foreignKey: {
          name: 'followed_creatorId',
      },
      constraints: false,
    });




    db.creator_profiles.hasMany(db.discovery_items, {
      as: 'discovery_items_creator',
      foreignKey: {
          name: 'creatorId',
      },
      constraints: false,
    });


    db.creator_profiles.hasMany(db.streams, {
      as: 'streams_creator',
      foreignKey: {
          name: 'creatorId',
      },
      constraints: false,
    });


    db.creator_profiles.hasMany(db.videos, {
      as: 'videos_creator',
      foreignKey: {
          name: 'creatorId',
      },
      constraints: false,
    });





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




    db.creator_profiles.hasMany(db.alerts, {
      as: 'alerts_creator',
      foreignKey: {
          name: 'creatorId',
      },
      constraints: false,
    });


    db.creator_profiles.hasMany(db.overlay_profiles, {
      as: 'overlay_profiles_creator',
      foreignKey: {
          name: 'creatorId',
      },
      constraints: false,
    });




    db.creator_profiles.hasMany(db.merch_stores, {
      as: 'merch_stores_creator',
      foreignKey: {
          name: 'creatorId',
      },
      constraints: false,
    });







    db.creator_profiles.hasMany(db.private_mailboxes, {
      as: 'private_mailboxes_owner_creator',
      foreignKey: {
          name: 'owner_creatorId',
      },
      constraints: false,
    });







//end loop



    db.creator_profiles.belongsTo(db.users, {
      as: 'user',
      foreignKey: {
        name: 'userId',
      },
      constraints: false,
    });

    db.creator_profiles.belongsTo(db.profile_styles, {
      as: 'profile_style',
      foreignKey: {
        name: 'profile_styleId',
      },
      constraints: false,
    });

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

    db.creator_profiles.belongsTo(db.merch_stores, {
      as: 'merch_store',
      foreignKey: {
        name: 'merch_storeId',
      },
      constraints: false,
    });

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




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

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



  return creator_profiles;
};


