'use strict';
/** @type {import('sequelize-cli').Migration} */
module.exports = {
  async up(queryInterface, Sequelize) {
    await queryInterface.createTable('Orders', {
      id: {
        allowNull: false,
        autoIncrement: true,
        primaryKey: true,
        type: Sequelize.INTEGER
      },
      userId: {
        type: Sequelize.INTEGER
      },
      orderNumber: {
        type: Sequelize.STRING,
        unique: true,
        allowNull: false
      },
      status: {
        type: Sequelize.ENUM(
          'pending',
          'confirmed',
          'processing',
          'shipped',
          'delivered',
          'cancelled',
          'refunded',
          'failed'
        ),
        allowNull: false,
        defaultValue: 'pending'
      },
      subtotal: {
        type: Sequelize.DECIMAL(10, 2)
      },
      tax: {
        type: Sequelize.DECIMAL(10, 2)
      },
      shippingCost: {
        type: Sequelize.DECIMAL(10, 2)
      },
      discount: {
        type: Sequelize.DECIMAL(10, 2)
      },
      total: {
        type: Sequelize.DECIMAL(10, 2),
        allowNull: false
      },
      paymentMethod: {
        type: Sequelize.STRING
      },
      paymentStatus: {
        type: Sequelize.ENUM(
          'pending',
          'authorized',
          'paid',
          'failed',
          'refunded',
          'partially_refunded',
          'cancelled'
        ),
        allowNull: false,
        defaultValue: 'pending'
      },
      shippingAddressId: {
        type: Sequelize.INTEGER
      },
      billingAddressId: {
        type: Sequelize.INTEGER
      },
      createdAt: {
        allowNull: false,
        type: Sequelize.DATE
      },
      updatedAt: {
        allowNull: false,
        type: Sequelize.DATE
      }
    });
  },
  async down(queryInterface, Sequelize) {
    await queryInterface.dropTable('Orders');
  }
};