<?php

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

class CreatePaymentMedicalServiceTable extends Migration
{
    public function up()
    {
        Schema::create('payment_medical_service', function (Blueprint $table) {
            $table->id();
            $table->string('payment_id');
            $table->unsignedBigInteger('medical_service_id');
            $table->decimal('cost', 10, 2);
            $table->timestamps();
            
            // We'll add the foreign key constraints separately after all tables exist
        });
        
        // Add foreign key constraints after all tables are created
        Schema::table('payment_medical_service', function (Blueprint $table) {
            $table->foreign('payment_id')->references('id')->on('payments')->onDelete('cascade');
            $table->foreign('medical_service_id')->references('id')->on('medical_services')->onDelete('cascade');
        });
    }

    public function down()
    {
        Schema::dropIfExists('payment_medical_service');
    }
}
