import { DataTypes } from 'sequelize';

export default function defineBooking(sequelize) {
  return sequelize.define(
    'Booking',
    {
      id: { type: DataTypes.BIGINT.UNSIGNED, primaryKey: true, autoIncrement: true },
      user_id: { type: DataTypes.BIGINT.UNSIGNED, allowNull: false },
      vehicle_id: { type: DataTypes.BIGINT.UNSIGNED, allowNull: false },
      service_id: { type: DataTypes.BIGINT.UNSIGNED, allowNull: false },
      booking_type: {
        type: DataTypes.ENUM('workshop', 'home'),
        allowNull: false,
        defaultValue: 'workshop',
      },
      home_address: { type: DataTypes.STRING(500), allowNull: true },
      contact_name: { type: DataTypes.STRING(120), allowNull: true },
      contact_phone: { type: DataTypes.STRING(20), allowNull: true },
      customer_note: { type: DataTypes.STRING(500), allowNull: true },
      status: {
        type: DataTypes.ENUM(
          'pending',
          'confirmed',
          'in_progress',
          'completed',
          'cancelled'
        ),
        allowNull: false,
        defaultValue: 'pending',
      },
      scheduled_date: { type: DataTypes.DATEONLY, allowNull: false },
      created_at: {
        type: DataTypes.DATE(3),
        allowNull: false,
        defaultValue: DataTypes.NOW,
      },
    },
    { tableName: 'bookings' }
  );
}
