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

name: {
        type: DataTypes.TEXT,
      
      

      },

description: {
        type: DataTypes.TEXT,
      
      

      },

deck_visibility: {
        type: DataTypes.ENUM,
      
      

        values: [

"private",


"workspace",


"public_link"

        ],

      },

generation_mode: {
        type: DataTypes.ENUM,
      
      

        values: [

"manual",


"ai_generated",


"mixed"

        ],

      },

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

      },

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

  flashcard_decks.associate = (db) => {


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




















    db.flashcard_decks.hasMany(db.flashcards, {
      as: 'flashcards_deck',
      foreignKey: {
          name: 'deckId',
      },
      constraints: false,
    });














//end loop



    db.flashcard_decks.belongsTo(db.workspaces, {
      as: 'workspace',
      foreignKey: {
        name: 'workspaceId',
      },
      constraints: false,
    });

    db.flashcard_decks.belongsTo(db.subjects, {
      as: 'subject',
      foreignKey: {
        name: 'subjectId',
      },
      constraints: false,
    });

    db.flashcard_decks.belongsTo(db.topics, {
      as: 'topic',
      foreignKey: {
        name: 'topicId',
      },
      constraints: false,
    });

    db.flashcard_decks.belongsTo(db.sources, {
      as: 'source',
      foreignKey: {
        name: 'sourceId',
      },
      constraints: false,
    });

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




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

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



  return flashcard_decks;
};


