תעשה הכנסת נתונים:'use strict';

/** @type {import('sequelize-cli').Migration} */
module.exports = {
  async up(queryInterface, Sequelize) {
    await queryInterface.createTable('parkingsessions', {
      id: {
        type: Sequelize.INTEGER,
        primaryKey: true,
        allowNull: false,
        autoIncrement: true,
      },
      baseuserid: {
        type: Sequelize.INTEGER,
        allowNull: false,
        references: {
          model: 'baseuser', // Reference to the baseuser table
          key: 'id',
        },
        onUpdate: 'CASCADE',
        onDelete: 'SET NULL',
      },
      vehicleid: {
        type: Sequelize.INTEGER,
        allowNull: false,
        references: {
          model: 'vehicles', // Reference to the vehicles table
          key: 'id',
        },
        onUpdate: 'CASCADE',
        onDelete: 'SET NULL',
      },
     parkingspotid: {
        type: Sequelize.INTEGER,
        allowNull: false,
        references: {
          model: 'parkingspots', // Reference to the parkingspots table
          key: 'id',
        },
        onUpdate: 'CASCADE',
        onDelete: 'SET NULL',
      },
      userid: {
        type: Sequelize.STRING,
        allowNull: false,
      },
      vehicleid: {
        type: Sequelize.STRING,
        allowNull: false,
      },
      licenseplate: {
        type: Sequelize.STRING,
        allowNull: false,
      },
      surfacespot: {
        type: Sequelize.STRING,
        allowNull: true,
      },
      undergroundspot: {
        type: Sequelize.STRING,
        allowNull: true,
      },
      status: {
        type: Sequelize.INTEGER,
        allowNull: false,
        comment: '1=parked, 2=retrieval_requested, 3=completed',
      },
      entrytime: {
        type: Sequelize.DATE,
        allowNull: false,
      },
      exittime: {
        type: Sequelize.DATE,
        allowNull: true,
      },
      retrievalrequesttime: {
        type: Sequelize.DATE,
        allowNull: true,
      },
      actualretrievaltime: {
        type: Sequelize.DATE,
        allowNull: true,
      },
      pickupspot: {
        type: Sequelize.STRING,
        allowNull: true,
      },
      requestedby: {
        type: Sequelize.INTEGER,
        allowNull: true,
        comment: '1=mobile, 2=tablet',
      },
    });

    await queryInterface.bulkInsert('parkingsessions', [
      {
        userid: 'user123',
        vehicleid: 'vehicle1',
        licenseplate: 'ABC123',
        surfacespot: '5',
        undergroundspot: null,
        status: 1, 
        entrytime: new Date('2025-07-15T07:00:00'),
        exittime: null,
        retrievalrequesttime: null,
        actualretrievaltime: null,
        pickupspot: null,
        requestedby: null,
      },
      {
        userid: 'user456',
        vehicleid: 'vehicle2',
        licenseplate: 'XYZ456',
        surfacespot: '2',
        undergroundspot: null,
        status: 2, 
        entrytime: new Date('2025-07-15T08:30:00'),
        exittime: null,
        retrievalrequesttime: new Date('2025-07-15T09:00:00'),
        actualretrievaltime: null,
        pickupspot: '6',
        requestedby: 1, 
      },
    ]);
  },

  async down(queryInterface, Sequelize) {
    await queryInterface.dropTable('parkingsessions');
  }
};