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

task_name: {
        type: DataTypes.TEXT,
      
      

      },

task_type: {
        type: DataTypes.ENUM,
      
      

        values: [

"profile_draft",


"vision_preview",


"career_coach_first_contact",


"tutor_in_lesson",


"learning_coach_checkin",


"rubric_spotcheck",


"other"

        ],

      },

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

      },

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

      },

per_user_daily_limit: {
        type: DataTypes.INTEGER,
      
      

      },

system_prompt_template: {
        type: DataTypes.TEXT,
      
      

      },

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

  ai_tasks.associate = (db) => {


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




















    db.ai_tasks.hasMany(db.ai_requests, {
      as: 'ai_requests_ai_task',
      foreignKey: {
          name: 'ai_taskId',
      },
      constraints: false,
    });









//end loop






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

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



  return ai_tasks;
};


