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

headline: {
        type: DataTypes.TEXT,
      
      

      },

teaching_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"university_student",


"certified_professional",


"experienced_teacher"

        ],

      },

institution_name: {
        type: DataTypes.TEXT,
      
      

      },

degree_qualification: {
        type: DataTypes.TEXT,
      
      

      },

graduation_year: {
        type: DataTypes.INTEGER,
      
      

      },

session_language: {
        type: DataTypes.ENUM,
      
      

        values: [

"bangla",


"english",


"both"

        ],

      },

teaching_format: {
        type: DataTypes.ENUM,
      
      

        values: [

"live_video",


"async_review",


"mixed"

        ],

      },

verification_status: {
        type: DataTypes.ENUM,
      
      

        values: [

"verified",


"pending",


"rejected"

        ],

      },

verification_note: {
        type: DataTypes.TEXT,
      
      

      },

rating: {
        type: DataTypes.DECIMAL,
      
      

      },

total_sessions: {
        type: DataTypes.INTEGER,
      
      

      },

total_reviews: {
        type: DataTypes.INTEGER,
      
      

      },

response_rate: {
        type: DataTypes.INTEGER,
      
      

      },

response_time_hours: {
        type: DataTypes.INTEGER,
      
      

      },

badge_level: {
        type: DataTypes.ENUM,
      
      

        values: [

"rising_talent",


"top_rated",


"expert",


"none"

        ],

      },

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

      },

max_concurrent_bookings: {
        type: DataTypes.INTEGER,
      
      

      },

jitsi_meet_meeting_id: {
        type: DataTypes.TEXT,
      
      

      },

jitsi_meet_password: {
        type: DataTypes.TEXT,
      
      

      },

availability_json: {
        type: DataTypes.TEXT,
      
      

      },

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

  tutor_profiles.associate = (db) => {

    db.tutor_profiles.belongsToMany(db.subject_categories, {
      as: 'subject_categories',
      foreignKey: {
        name: 'tutor_profiles_subject_categoriesId',
      },
      constraints: false,
      through: 'tutor_profilesSubject_categoriesSubject_categories',
    });

    db.tutor_profiles.belongsToMany(db.subject_categories, {
      as: 'subject_categories_filter',
      foreignKey: {
        name: 'tutor_profiles_subject_categoriesId',
      },
      constraints: false,
      through: 'tutor_profilesSubject_categoriesSubject_categories',
    });

    db.tutor_profiles.belongsToMany(db.subjects, {
      as: 'subjects',
      foreignKey: {
        name: 'tutor_profiles_subjectsId',
      },
      constraints: false,
      through: 'tutor_profilesSubjectsSubjects',
    });

    db.tutor_profiles.belongsToMany(db.subjects, {
      as: 'subjects_filter',
      foreignKey: {
        name: 'tutor_profiles_subjectsId',
      },
      constraints: false,
      through: 'tutor_profilesSubjectsSubjects',
    });

    db.tutor_profiles.belongsToMany(db.languages, {
      as: 'languages',
      foreignKey: {
        name: 'tutor_profiles_languagesId',
      },
      constraints: false,
      through: 'tutor_profilesLanguagesLanguages',
    });

    db.tutor_profiles.belongsToMany(db.languages, {
      as: 'languages_filter',
      foreignKey: {
        name: 'tutor_profiles_languagesId',
      },
      constraints: false,
      through: 'tutor_profilesLanguagesLanguages',
    });


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










    db.tutor_profiles.hasMany(db.gigs, {
      as: 'gigs_tutor_profile',
      foreignKey: {
          name: 'tutor_profileId',
      },
      constraints: false,
    });



































//end loop



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



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


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

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



  return tutor_profiles;
};


