<?php

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

class CreatePatientCustomFieldsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('patient_custom_fields', function (Blueprint $table) {
            $table->id();
            $table->string('name'); // Field name (e.g., 'Insurance Number')
            $table->string('type')->default('text'); // Field type (text, number, date, etc.)
            $table->json('options')->nullable(); // Additional options (like select options)
            $table->string('placeholder')->nullable(); // Placeholder text for the field
            $table->boolean('required')->default(false); // Whether field is required
            $table->integer('order')->default(0); // For custom ordering of fields
            $table->boolean('active')->default(true); // To enable/disable fields
            $table->unsignedBigInteger('created_by'); // User who created the field
            $table->timestamps();
            
            $table->foreign('created_by')->references('id')->on('users')->onDelete('cascade');
        });
    }

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