const { DataTypes } = require('sequelize');
const { sequelize } = require('../config/database');

const Booking = sequelize.define('bookings', {
  id: { type: DataTypes.INTEGER, primaryKey: true, autoIncrement: true },
  booking_reference: { type: DataTypes.STRING(20), unique: true, allowNull: false },
  schedule_id: { type: DataTypes.INTEGER, allowNull: false },
  customer_id: { type: DataTypes.INTEGER },
  customer_name: { type: DataTypes.STRING(100), allowNull: false },
  customer_email: { type: DataTypes.STRING(100), allowNull: false },
  customer_phone: { type: DataTypes.STRING(20), allowNull: false },
  pickup_address: { type: DataTypes.STRING(255) },
  pickup_landmark: { type: DataTypes.STRING(100) },
  dropoff_address: { type: DataTypes.STRING(255) },
  dropoff_landmark: { type: DataTypes.STRING(100) },
  number_of_passengers: { type: DataTypes.INTEGER, defaultValue: 1, allowNull: false },
  total_amount: { type: DataTypes.DECIMAL(10, 2), allowNull: false },
  deposit_amount: { type: DataTypes.DECIMAL(10, 2), allowNull: false },
  balance_amount: { type: DataTypes.DECIMAL(10, 2), allowNull: false },
  booking_status: { type: DataTypes.ENUM('pending', 'POP_uploaded', 'pending_approval', 'confirmed', 'completed', 'cancelled'), defaultValue: 'pending' },
  payment_status: { type: DataTypes.ENUM('unpaid', 'deposit_only', 'fully_paid'), defaultValue: 'unpaid' },
  proof_of_payment: { type: DataTypes.STRING(500) },
  special_requests: { type: DataTypes.TEXT },
  is_door_to_door: { type: DataTypes.BOOLEAN, defaultValue: false },
  image_url: { type: DataTypes.STRING(500) },
  reminder_24h_sent_at: { type: DataTypes.DATE, allowNull: true },
  reminder_2h_sent_at: { type: DataTypes.DATE, allowNull: true },
  trip_started_notified_at: { type: DataTypes.DATE, allowNull: true },
  trip_ended_notified_at: { type: DataTypes.DATE, allowNull: true },
}, {
  timestamps: true,
  createdAt: 'created_at',
  updatedAt: 'updated_at',
});

module.exports = Booking;
