<?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('ticket_replies', function (Blueprint $table) {
            $table->id();
            $table->unsignedInteger('ticket_id'); // Destek talebi ile ilişkilendirilecek
            $table->unsignedInteger('client_id')->nullable(); // Yanıtlayan kullanıcı
            $table->unsignedBigInteger('admin_id')->nullable();
            $table->unsignedInteger('contact_id')->nullable(); // Yanıtlayan iletişim bilgisi
            $table->string('mail'); // Yanıtlayan e-posta adresi
            $table->text('message'); // Yanıt mesajı
            $table->boolean('is_internal')->default(false);
            $table->timestamps();

            $table->foreign('admin_id')->references('id')->on('admins')->onDelete('set null');
            $table->index('admin_id');
        });
    }

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