'use strict';
/** @type {import('sequelize-cli').Migration} */
module.exports = {
  async up (queryInterface, Sequelize) {
    await queryInterface.createTable('bookings', {
      booking_id: {
        allowNull: false,
        autoIncrement: true,
        primaryKey: true,
        type: Sequelize.DataTypes.INTEGER
      },
      client_id: {
        type: Sequelize.DataTypes.INTEGER,
        allowNull: false,
        references: {
          model: 'clients',
          key: 'client_id'
        },
        onDelete: 'RESTRICT',
        onUpdate: 'CASCADE',
        comment: 'ID клиента'
      },
      hall_id: {
        type: Sequelize.DataTypes.INTEGER,
        allowNull: false,
        references: {
          model: 'halls',
          key: 'hall_id'
        },
        onDelete: 'RESTRICT',
        onUpdate: 'CASCADE',
        comment: 'ID зала'
      },
      photographer_id: {
        type: Sequelize.DataTypes.INTEGER,
        allowNull: true,
        references: {
          model: 'photographers',
          key: 'photographer_id'
        },
        onDelete: 'SET NULL',
        onUpdate: 'CASCADE',
        comment: 'ID фотографа'
      },
      start_time: {
        type: Sequelize.DataTypes.DATE,
        allowNull: false,
        comment: 'Время начала'
      },
      end_time: {
        type: Sequelize.DataTypes.DATE,
        allowNull: false,
        comment: 'Время окончания'
      },
      total_cost: {
        type: Sequelize.DataTypes.DECIMAL(10, 2),
        allowNull: true,
        comment: 'Общая стоимость'
      },
      status: {
        type: Sequelize.DataTypes.ENUM('pending', 'confirmed', 'completed', 'cancelled'),
        allowNull: true,
        defaultValue: 'pending',
        comment: 'Статус бронирования'
      },
      created_at: {
        type: Sequelize.DataTypes.DATE,
        allowNull: true,
        defaultValue: Sequelize.literal('CURRENT_TIMESTAMP'),
        comment: 'Дата создания'
      }
    })
  },
  async down (queryInterface, Sequelize) {
    await queryInterface.dropTable('bookings')
  }
}