<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('vehicle_type_pricing', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('tenant_id');
            $table->unsignedBigInteger('vehicle_type_id');
            $table->decimal('base_fare', 10, 2); // Base fare for booking
            $table->decimal('per_km_rate', 10, 2)->nullable(); // Rate per km
            $table->decimal('per_minute_rate', 10, 2)->nullable(); // Rate per minute
            $table->decimal('minimum_fare', 10, 2)->nullable(); // Minimum fare
            $table->string('currency')->default('INR'); // Currency
            $table->string('pricing_type')->default('fixed'); // fixed, dynamic, hybrid
            $table->boolean('is_active')->default(true);
            $table->dateTime('valid_from')->nullable();
            $table->dateTime('valid_until')->nullable();
            $table->timestamps();
            
            $table->foreign('tenant_id')->references('id')->on('tenants')->onDelete('cascade');
            $table->foreign('vehicle_type_id')->references('id')->on('vehicle_types')->onDelete('cascade');
            $table->unique(['tenant_id', 'vehicle_type_id']);
            $table->index('is_active');
        });
    }

    /**
     * Reverse the migrations.
     */
    public function down(): void
    {
        Schema::dropIfExists('vehicle_type_pricing');
    }
};
