<?php

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

return new class extends Migration
{
  
    public function up(): void
    {
        Schema::create('hcp_ratings', function (Blueprint $table) {
            $table->id('rating_id'); 
            $table->unsignedBigInteger('hcp_id'); 
            $table->unsignedBigInteger('patient_id'); 
            $table->integer('rating'); 
            $table->text('review')->nullable(); 
            $table->timestamps(0); 

            $table->foreign('hcp_id')->references('hcp_id')->on('hcp')->onUpdate('no action')->onDelete('no action');
            $table->foreign('patient_id')->references('patient_id')->on('patient')->onUpdate('no action')->onDelete('no action');
        });

        
        DB::statement('ALTER TABLE hcp_ratings ADD CONSTRAINT hcp_ratings_rating_check CHECK (rating >= 1 AND rating <= 5)');
    }

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