'use strict';
/** @type {import('sequelize-cli').Migration} */
module.exports = {
  async up(queryInterface, Sequelize) {
    await queryInterface.createTable('Carts', {
      id: {
        allowNull: false,
        autoIncrement: true,
        primaryKey: true,
        type: Sequelize.INTEGER
      },
      userId: {
        type: Sequelize.INTEGER
      },
      sessionId: {
        type: Sequelize.STRING
      },
      status: {
        type: Sequelize.ENUM(
          'active',
          'abandoned',
          'converted',
          'expired',
          'merged'
        ),
        allowNull: false,
        defaultValue: 'active'
      },
      expiresAt: {
        type: Sequelize.DATE
      },
      createdAt: {
        allowNull: false,
        type: Sequelize.DATE
      },
      updatedAt: {
        allowNull: false,
        type: Sequelize.DATE
      }
    });

    // Add indexes for better performance
    await queryInterface.addIndex('Carts', ['userId']);
    await queryInterface.addIndex('Carts', ['sessionId']);
    await queryInterface.addIndex('Carts', ['status']);
  },
  async down(queryInterface, Sequelize) {
    await queryInterface.dropTable('Carts');
  }
};