<?php

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

class CreateVcDoctorSchedulesTable extends Migration
{
    public function up()
    {
        if (!Schema::hasTable('vc_doctor_schedules')) {
            Schema::create('vc_doctor_schedules', function (Blueprint $table) {
                $table->increments('id');
                $table->unsignedInteger('doctor_id');
                $table->unsignedInteger('department_id')->nullable();
                // 0=Sunday … 6=Saturday
                $table->unsignedTinyInteger('day_of_week');
                $table->time('start_time');
                $table->time('end_time');
                // slot duration in minutes (e.g. 15, 20, 30)
                $table->unsignedSmallInteger('slot_duration_minutes')->default(30);
                $table->enum('status', ['active', 'inactive'])->default('active');
                $table->timestamps();

                $table->foreign('doctor_id')->references('id')->on('vc_doctors')->onDelete('cascade');
                $table->foreign('department_id')->references('id')->on('vc_departments')->onDelete('cascade');
                $table->index(['doctor_id', 'department_id', 'day_of_week']);
            });
        }
    }

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