<?php

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

return new class extends Migration
{
    /**
     * Zaman tüneli zenginleştirme:
     * - task_comments.links: modül referansları (chat'teki link paylaşımı mantığı)
     *   [{key: "sale:5", label: "Satış · SAL-123"}, ...]
     * - task_comment_attachments: nota eklenen dosyalar (png, pdf, excel vb. tüm tipler)
     */
    public function up(): void
    {
        Schema::table('task_comments', function (Blueprint $table) {
            $table->json('links')->nullable()->after('body');
        });

        Schema::create('task_comment_attachments', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('task_comment_id');
            $table->string('path', 500);
            $table->string('original_name', 255);
            $table->string('mime_type', 120)->nullable();
            $table->unsignedBigInteger('size')->default(0);
            $table->string('kind', 12)->default('file'); // image | file
            $table->timestamps();

            $table->foreign('task_comment_id')->references('id')->on('task_comments')->onDelete('cascade');
            $table->index('task_comment_id');
        });
    }

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

        Schema::table('task_comments', function (Blueprint $table) {
            $table->dropColumn('links');
        });
    }
};
