const dbConfig = require("../config/db.config.js");

const Sequelize = require("sequelize");
const sequelize = new Sequelize(dbConfig.DB, dbConfig.USER, dbConfig.PASSWORD, {
  host: dbConfig.HOST,
  dialect: dbConfig.dialect,
  operatorsAliases: false,
  dialectOptions: {
    multipleStatements: true,
  },
  pool: {
    max: dbConfig.pool.max,
    min: dbConfig.pool.min,
    acquire: dbConfig.pool.acquire,
    idle: dbConfig.pool.idle
  }
});

const db = {};

db.Sequelize = Sequelize;
db.sequelize = sequelize;

db.AccessDuration = require("./access_durations.js")(sequelize, Sequelize);
db.AccessMster = require("./access_masters.js")(sequelize, Sequelize);
db.Acronyms = require("./acronyms.js")(sequelize, Sequelize);
db.ActivityTracker = require("./activity_trackers.js")(sequelize, Sequelize);
db.AdminLogs = require("./admin_logs.js")(sequelize, Sequelize);
db.AIAssignedQuestion = require("./ai_assigned_questions.js")(sequelize, Sequelize);
db.AIQuestionFeedbacks = require("./ai_question_feedbacks.js")(sequelize, Sequelize);
db.AIQuestions = require("./ai_questions.js")(sequelize, Sequelize);
db.AIUsers = require("./ai_users.js")(sequelize, Sequelize);
db.AllLiveEvent = require("./all_live_events.js")(sequelize, Sequelize);
db.AppSupport = require("./app_support.js")(sequelize, Sequelize);
db.AuthyMaster = require("./authy_masters.js")(sequelize, Sequelize);
db.Books = require("./books.js")(sequelize, Sequelize);
db.BucketUpload = require("./bucket_uploads.js")(sequelize, Sequelize);
db.CardView = require("./card_views.js")(sequelize, Sequelize);
db.Certificate = require("./Certificates.js")(sequelize, Sequelize);
db.Chatting = require("./chattings.js")(sequelize, Sequelize);
db.ClientCohort = require("./ClientCohorts.js")(sequelize, Sequelize);
db.ClientLogs = require("./client_logs.js")(sequelize, Sequelize);
db.Cohort = require("./Cohorts.js")(sequelize, Sequelize);
db.CohortSchedule = require("./Cohort_Schedule.js")(sequelize, Sequelize);
db.Company = require("./companies.js")(sequelize, Sequelize);
db.Cource = require("./Cources.js")(sequelize, Sequelize);
db.Ctestcomplate = require("./cat_complated.js")(sequelize, Sequelize);
db.Discussion = require("./Discussion.js")(sequelize, Sequelize);
db.Domain = require("./Domains.js")(sequelize, Sequelize);
db.EmailTemplates = require("./email_templates.js")(sequelize, Sequelize);
db.Enrolluser = require("./Enroll_users.js")(sequelize, Sequelize);
db.EventRecording = require("./event_recordings.js")(sequelize, Sequelize);
db.FailedEmail = require("./failed_emails.js")(sequelize, Sequelize);
db.FlashAnsOffline = require("./Flashans_offline.js")(sequelize, Sequelize);
db.FlashappSync = require("./Flashapp_sync.js")(sequelize, Sequelize);
db.Flashcard = require("./Flashcards.js")(sequelize, Sequelize);
db.FlashCardAns = require("./Flash_card_ans.js")(sequelize, Sequelize);
db.FlashCardOffline = require("./Flashans_offline.js")(sequelize, Sequelize);
db.FlashcardReviews = require("./flashcard_reviews.js")(sequelize, Sequelize);
db.HybridClass = require("./hybrid_class.js")(sequelize, Sequelize);
db.HybridSchedule = require("./Hybrid_Schedule.js")(sequelize, Sequelize);
db.HybridTemplates = require("./Hybrid_Templates.js")(sequelize, Sequelize);
db.HybridTemplatesSchedule = require("./Hybrid_Templates_Schedule.js")(sequelize, Sequelize);
db.KaComplete = require("./know_completed.js")(sequelize, Sequelize);
db.KetexamAns = require("./KetExamAns.js")(sequelize, Sequelize);
db.Ketexamque = require("./Ketexam_ques.js")(sequelize, Sequelize);
db.Ketexamtest = require("./Ketexamtest.js")(sequelize, Sequelize);
db.KnowAssQues = require("./Know_ass_ques.js")(sequelize, Sequelize);
db.KnowAssQuesAns = require("./Know_ass_q_ans.js")(sequelize, Sequelize);
db.KnowledgeAsses = require("./Knowledge_asses.js")(sequelize, Sequelize);
db.Liveans = require("./Livequestion_ans.js")(sequelize, Sequelize);
db.LiveEvents = require("./live_events.js")(sequelize, Sequelize);
db.Liveques = require("./Livequestions.js")(sequelize, Sequelize);
db.Livetest = require("./Live_test.js")(sequelize, Sequelize);
db.LoginLogs = require("./login_logs.js")(sequelize, Sequelize);
db.MasterPlan = require("./master_plans.js")(sequelize, Sequelize);
db.MeetingChats = require("./meeting_chats.js")(sequelize, Sequelize);
db.Meetings = require("./meetings.js")(sequelize, Sequelize);
db.MindMap = require("./mind_maps.js")(sequelize, Sequelize);
db.MiniMasterClass = require("./mini_master_class.js")(sequelize, Sequelize);
db.MiniMasterClassKaComplete = require("./mini_master_class_ka_completes.js")(sequelize, Sequelize);
db.MiniMasterClassKaqa = require("./mini_master_class_kaq_ans.js")(sequelize, Sequelize);
db.MiniMasterClassPtComplete = require("./mini_master_class_pt_completes.js")(sequelize, Sequelize);
db.MiniMasterClassPtqa = require("./mini_master_class_ptq_ans.js")(sequelize, Sequelize);
db.MiniMasterCompleteClass = require("./mini_master_completed_class.js")(sequelize, Sequelize);
db.Navigation = require("./app_nav_setting.js")(sequelize, Sequelize);
db.Notes = require("./Notes.js")(sequelize, Sequelize);
db.Notifications = require("./notifications.js")(sequelize, Sequelize);
db.NotificationSetting = require("./notification_settings.js")(sequelize, Sequelize);
db.Onbording = require("./onbordings.js")(sequelize, Sequelize);
db.PasswordReset = require("./Password_resets.js")(sequelize, Sequelize);
db.PaymentTransaction = require("./payment_transactions.js")(sequelize, Sequelize);
db.Plans = require("./plans.js")(sequelize, Sequelize);
db.PlanWiseAccess = require("./plan_wise_access.js")(sequelize, Sequelize);
db.Points = require("./points.js")(sequelize, Sequelize);
db.PracticeAns = require("./PracticeAns.js")(sequelize, Sequelize);
db.PracticeAppAns = require("./practiceapp_ans.js")(sequelize, Sequelize);
db.PracticeAppLastAns = require("./practiceapp_lastans.js")(sequelize, Sequelize);
db.PracticeAppque = require("./Practice_appques.js")(sequelize, Sequelize);
db.Practiceque = require("./Practiceques.js")(sequelize, Sequelize);
db.Practicetest = require("./Practicetests.js")(sequelize, Sequelize);
db.PrAppAnsOffline = require("./prappans_offline.js")(sequelize, Sequelize);
db.Ptestcomplate = require("./practice_complated.js")(sequelize, Sequelize);
db.QueDBUpdate = require("./quedb_update.js")(sequelize, Sequelize);
db.QuestionDiscussion = require("./QuestionDiscussion.js")(sequelize, Sequelize);
db.QuestionNotes = require("./question_notes.js")(sequelize, Sequelize);
db.References = require("./References.js")(sequelize, Sequelize);
db.Result = require("./Result.js")(sequelize, Sequelize);
db.Role = require("./Roles.js")(sequelize, Sequelize);
db.Schedule = require("./Schedule.js")(sequelize, Sequelize);
db.ScheduleTime = require("./Shedule_time.js")(sequelize, Sequelize);
db.Scores = require("./scores.js")(sequelize, Sequelize);
db.SelfPaced = require("./self_paced.js")(sequelize, Sequelize);
db.SelfpacedClassAllUserSchedule = require("./selfpaced_class_all_user_schedule.js")(sequelize, Sequelize);
db.SelfPacedHour = require("./self_paced_hours.js")(sequelize, Sequelize);
db.SelfPacedMaterial = require("./self_paced_materials.js")(sequelize, Sequelize);
db.SelfPacedOneTime = require("./self_paced_one_times.js")(sequelize, Sequelize);
db.SelfPacedSchedule = require("./self_paced_schedules.js")(sequelize, Sequelize);
db.SelfPacedSubscription = require("./self_paced_subscriptions.js")(sequelize, Sequelize);
db.ShortUrl = require("./shorturl.js")(sequelize, Sequelize);
db.Socket = require("./Sockets.js")(sequelize, Sequelize);
db.StudyMaterial = require("./Study_materials.js")(sequelize, Sequelize);
db.StudyMatFeedback = require("./Study_mat_feedback.js")(sequelize, Sequelize);
db.Subdomain = require("./Subdomains.js")(sequelize, Sequelize);
db.SubTopic = require("./SubTopic.js")(sequelize, Sequelize);
db.TakeSurvey = require("./take_surveys.js")(sequelize, Sequelize);
db.TeacherAccess = require("./teacher_access.js")(sequelize, Sequelize);
db.Templates = require("./Templates.js")(sequelize, Sequelize);
db.TemplateSchedule = require("./Templates_Schedule.js")(sequelize, Sequelize);
db.TestLogs = require("./test_logs.js")(sequelize, Sequelize);
db.Topic = require("./Topics.js")(sequelize, Sequelize);
db.UserLogs = require("./user_logs.js")(sequelize, Sequelize);
db.Variables = require("./variables.js")(sequelize, Sequelize);
db.Version = require("./Version.js")(sequelize, Sequelize);
db.Video = require("./Video.js")(sequelize, Sequelize);
db.VideoDiscussion = require("./VideoDiscussion.js")(sequelize, Sequelize);
db.VideoMindView = require("./video_mind_views.js")(sequelize, Sequelize);
db.VideoNotes = require("./Video_notes.js")(sequelize, Sequelize);
db.VideoSectionView = require("./video_section_views.js")(sequelize, Sequelize);
db.User = require("./users.model.js")(sequelize, Sequelize);

//  ---------------------------Foreign Keys---------------------------
db.Acronyms.belongsTo(db.Certificate, { foreignKey: 'certi_id', targetKey: 'id' });
db.AIQuestions.belongsTo(db.Certificate, { foreignKey: 'certi_id', targetKey: 'id' });
db.AIQuestions.belongsTo(db.Domain, { foreignKey: 'd_id', targetKey: 'id' });
db.AppSupport.belongsTo(db.User, { foreignKey: 'user_id', targetKey: 'id' });
db.Books.belongsTo(db.Certificate, { foreignKey: 'certi_id', targetKey: 'id' });
db.Chatting.belongsTo(db.User, { foreignKey: 'user_id', targetKey: 'id' });
db.Cohort.belongsTo(db.Certificate, { foreignKey: 'certi_id', targetKey: 'id' });
db.Cohort.belongsTo(db.Cource, { foreignKey: 'cource_id', targetKey: 'id' });
db.Cource.belongsTo(db.Certificate, { foreignKey: 'certi_id', targetKey: 'id' });
db.Domain.belongsTo(db.Certificate, { foreignKey: 'certi_id', targetKey: 'id' });
db.Domain.belongsTo(db.Cource, { foreignKey: 'cource_id', targetKey: 'id' });
db.EmailTemplates.belongsTo(db.Certificate, { foreignKey: 'certi_id', targetKey: 'id' });
db.Flashcard.belongsTo(db.Certificate, { foreignKey: 'certi_id', targetKey: 'id' });
db.Flashcard.belongsTo(db.Cource, { foreignKey: 'cource_id', targetKey: 'id' });
db.Flashcard.belongsTo(db.Domain, { foreignKey: 'd_id', targetKey: 'id' });
db.Flashcard.belongsTo(db.Subdomain, { foreignKey: 'sd_id', targetKey: 'id' });
db.Flashcard.belongsTo(db.Topic, { foreignKey: 'topic_id', targetKey: 'id' });
db.HybridTemplates.belongsTo(db.Certificate, { foreignKey: 'certi_id', targetKey: 'id' });
db.Ketexamque.belongsTo(db.Certificate, { foreignKey: 'certi_id', targetKey: 'id' });
db.Ketexamque.belongsTo(db.Domain, { foreignKey: 'd_id', targetKey: 'id' });
db.Ketexamque.belongsTo(db.Ketexamtest, { foreignKey: 'test_id', targetKey: 'id' });
db.Ketexamque.belongsTo(db.Subdomain, { foreignKey: 'sd_id', targetKey: 'id' });
db.Ketexamque.belongsTo(db.Topic, { foreignKey: 'topic_id', targetKey: 'id' });
db.Ketexamtest.belongsTo(db.Certificate, { foreignKey: 'certi_id', targetKey: 'id' });
db.KnowAssQues.belongsTo(db.Certificate, { foreignKey: 'certi_id', targetKey: 'id' });
db.KnowAssQues.belongsTo(db.Domain, { foreignKey: 'd_id', targetKey: 'id' });
db.KnowAssQues.belongsTo(db.Subdomain, { foreignKey: 'sd_id', targetKey: 'id' });
db.KnowAssQues.belongsTo(db.Topic, { foreignKey: 'topic_id', targetKey: 'id' });
db.KnowledgeAsses.belongsTo(db.Certificate, { foreignKey: 'certi_id', targetKey: 'id' });
db.KnowledgeAsses.belongsTo(db.Cource, { foreignKey: 'cource_id', targetKey: 'id' });
db.LiveEvents.belongsTo(db.Certificate, { foreignKey: 'certi_id', targetKey: 'id' });
db.Liveques.belongsTo(db.Certificate, { foreignKey: 'certi_id', targetKey: 'id' });
db.Liveques.belongsTo(db.Domain, { foreignKey: 'd_id', targetKey: 'id' });
db.Liveques.belongsTo(db.Subdomain, { foreignKey: 'sd_id', targetKey: 'id' });
db.Liveques.belongsTo(db.Topic, { foreignKey: 'topic_id', targetKey: 'id' })
db.Livetest.belongsTo(db.Certificate, { foreignKey: 'certi_id', targetKey: 'id' });
db.LoginLogs.belongsTo(db.User, { foreignKey: 'user_id', targetKey: 'id' });
db.MeetingChats.belongsTo(db.User, { foreignKey: 'user_id', targetKey: 'id' });
db.MindMap.belongsTo(db.Certificate, { foreignKey: 'certi_id', targetKey: 'id' });
db.MindMap.belongsTo(db.Domain, { foreignKey: 'd_id', targetKey: 'id' });
db.MiniMasterClass.belongsTo(db.Certificate, { foreignKey: 'certi_id', targetKey: 'id' });
db.Notes.belongsTo(db.Domain, { foreignKey: 'domain_id', targetKey: 'id' })
db.PaymentTransaction.belongsTo(db.Certificate, { foreignKey: 'certi_id', targetKey: 'id' });
db.PracticeAppque.belongsTo(db.Certificate, { foreignKey: 'certi_id', targetKey: 'id' });
db.PracticeAppque.belongsTo(db.Cource, { foreignKey: 'cource_id', targetKey: 'id' });
db.PracticeAppque.belongsTo(db.Domain, { foreignKey: 'd_id', targetKey: 'id' });
db.PracticeAppque.belongsTo(db.Subdomain, { foreignKey: 'sd_id', targetKey: 'id' });
db.PracticeAppque.belongsTo(db.Topic, { foreignKey: 'topic_id', targetKey: 'id' });
db.Practiceque.belongsTo(db.Certificate, { foreignKey: 'certi_id', targetKey: 'id' });
db.Practiceque.belongsTo(db.Domain, { foreignKey: 'd_id', targetKey: 'id' });
db.Practiceque.belongsTo(db.Practicetest, { foreignKey: 'test_id', targetKey: 'id' });
db.Practiceque.belongsTo(db.Subdomain, { foreignKey: 'sd_id', targetKey: 'id' });
db.Practiceque.belongsTo(db.Topic, { foreignKey: 'topic_id', targetKey: 'id' });
db.Practicetest.belongsTo(db.Certificate, { foreignKey: 'certi_id', targetKey: 'id' });
db.QueDBUpdate.belongsTo(db.PracticeAppque, { foreignKey: 'queid', targetKey: 'id' });
db.QueDBUpdate.belongsTo(db.User, { foreignKey: 'user_id', targetKey: 'id' });
db.QuestionDiscussion.belongsTo(db.User, { foreignKey: 'user_id', targetKey: 'id' })
db.References.belongsTo(db.Books, { foreignKey: 'book_id', targetKey: 'id' });
db.References.belongsTo(db.Certificate, { foreignKey: 'certi_id', targetKey: 'id' })
db.References.belongsTo(db.Cource, { foreignKey: 'cource_id', targetKey: 'id' })
db.References.belongsTo(db.Domain, { foreignKey: 'd_id', targetKey: 'id' })
db.References.belongsTo(db.Subdomain, { foreignKey: 'sd_id', targetKey: 'id' })
db.References.belongsTo(db.SubTopic, { foreignKey: 'subtopic_id', targetKey: 'id' });
db.References.belongsTo(db.Topic, { foreignKey: 'topic_id', targetKey: 'id' });
db.ScheduleTime.belongsTo(db.Cohort, { foreignKey: 'cohort_id', targetKey: 'id' })
db.ScheduleTime.belongsTo(db.Templates, { foreignKey: 'template_id', targetKey: 'id' })
db.SelfPaced.belongsTo(db.Certificate, { foreignKey: 'certi_id', targetKey: 'id' });
db.SelfPacedOneTime.belongsTo(db.Certificate, { foreignKey: 'certi_id', targetKey: 'id' });
db.SelfPacedSubscription.belongsTo(db.Certificate, { foreignKey: 'certi_id', targetKey: 'id' });
db.StudyMaterial.belongsTo(db.Certificate, { foreignKey: 'certi_id', targetKey: 'id' });
db.StudyMaterial.belongsTo(db.Cource, { foreignKey: 'cource_id', targetKey: 'id' });
db.StudyMaterial.belongsTo(db.Domain, { foreignKey: 'd_id', targetKey: 'id' });
db.StudyMaterial.belongsTo(db.Subdomain, { foreignKey: 'sd_id', targetKey: 'id' });
db.StudyMaterial.belongsTo(db.Topic, { foreignKey: 'topic_id', targetKey: 'id' });
db.Subdomain.belongsTo(db.Certificate, { foreignKey: 'certi_id', targetKey: 'id' });
db.Subdomain.belongsTo(db.Cource, { foreignKey: 'cource_id', targetKey: 'id' });
db.Subdomain.belongsTo(db.Domain, { foreignKey: 'd_id', targetKey: 'id' });
db.SubTopic.belongsTo(db.Cource, { foreignKey: 'cource_id', targetKey: 'id' })
db.SubTopic.belongsTo(db.Domain, { foreignKey: 'd_id', targetKey: 'id' })
db.SubTopic.belongsTo(db.Subdomain, { foreignKey: 'sd_id', targetKey: 'id' })
db.SubTopic.belongsTo(db.Topic, { foreignKey: 'topic_id', targetKey: 'id' })
db.TeacherAccess.belongsTo(db.User, { foreignKey: 'user_id', targetKey: 'id' });
db.Templates.belongsTo(db.Certificate, { foreignKey: 'certi_id', targetKey: 'id' });
db.Templates.belongsTo(db.Cource, { foreignKey: 'cource_id', targetKey: 'id' });
db.TestLogs.belongsTo(db.User, { foreignKey: 'user_id', targetKey: 'id' });
db.Topic.belongsTo(db.Certificate, { foreignKey: 'certi_id', targetKey: 'id' });
db.Topic.belongsTo(db.Cource, { foreignKey: 'cource_id', targetKey: 'id' });
db.Topic.belongsTo(db.Domain, { foreignKey: 'd_id', targetKey: 'id' });
db.Topic.belongsTo(db.Subdomain, { foreignKey: 'sd_id', targetKey: 'id' });
db.UserLogs.belongsTo(db.User, { foreignKey: 'user_id', targetKey: 'id' });
db.Video.belongsTo(db.Certificate, { foreignKey: 'certi_id', targetKey: 'id' });
db.Video.belongsTo(db.Cource, { foreignKey: 'c_id', targetKey: 'id' })
db.Video.belongsTo(db.Domain, { foreignKey: 'd_id', targetKey: 'id' })
db.VideoDiscussion.belongsTo(db.User, { foreignKey: 'from', targetKey: 'id' })


module.exports = db;
