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

store_name: {
        type: DataTypes.TEXT,
      
      

      },

slug: {
        type: DataTypes.TEXT,
      
      

      },

store_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"draft",


"published",


"suspended"

        ],

      },

tagline: {
        type: DataTypes.TEXT,
      
      

      },

about: {
        type: DataTypes.TEXT,
      
      

      },

whatsapp_number: {
        type: DataTypes.TEXT,
      
      

      },

instagram_handle: {
        type: DataTypes.TEXT,
      
      

      },

tiktok_handle: {
        type: DataTypes.TEXT,
      
      

      },

custom_domain: {
        type: DataTypes.TEXT,
      
      

      },

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

  reseller_stores.associate = (db) => {


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























    db.reseller_stores.hasMany(db.store_pages, {
      as: 'store_pages_reseller_store',
      foreignKey: {
          name: 'reseller_storeId',
      },
      constraints: false,
    });






//end loop



    db.reseller_stores.belongsTo(db.tenants, {
      as: 'tenant',
      foreignKey: {
        name: 'tenantId',
      },
      constraints: false,
    });

    db.reseller_stores.belongsTo(db.users, {
      as: 'owner_user',
      foreignKey: {
        name: 'owner_userId',
      },
      constraints: false,
    });

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



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


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

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



  return reseller_stores;
};


