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

session_token: {
        type: DataTypes.TEXT,
      
      

      },

status: {
        type: DataTypes.ENUM,
      
      

        values: [

"active",


"converted",


"abandoned"

        ],

      },

expires_at: {
        type: DataTypes.DATE,
      
      

      },

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

  carts.associate = (db) => {


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












    db.carts.hasMany(db.cart_items, {
      as: 'cart_items_cart',
      foreignKey: {
          name: 'cartId',
      },
      constraints: false,
    });

















//end loop



    db.carts.belongsTo(db.users, {
      as: 'customer',
      foreignKey: {
        name: 'customerId',
      },
      constraints: false,
    });




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

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



  return carts;
};


