<?php

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

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('meeting_minute_segments', function (Blueprint $table) {
            $table->id()->comment('ID');
            $table->unsignedBigInteger('meeting_minute_id')->comment('회의록 ID');
            $table->unsignedInteger('segment_order')->comment('세그먼트 순서');

            $table->string('speaker_name', 100)->default('화자 1')->comment('화자 이름');
            $table->string('speaker_label', 20)->nullable()->comment('화자 라벨');
            $table->text('text')->comment('발화 텍스트');

            $table->unsignedInteger('start_time_ms')->default(0)->comment('시작 시간(ms)');
            $table->unsignedInteger('end_time_ms')->nullable()->comment('종료 시간(ms)');
            $table->boolean('is_manual_speaker')->default(true)->comment('수동 화자 전환 여부');

            $table->timestamps();

            $table->index('meeting_minute_id', 'idx_mms_meeting');
            $table->index(['meeting_minute_id', 'segment_order'], 'idx_mms_meeting_order');

            $table->foreign('meeting_minute_id', 'fk_mms_meeting')
                ->references('id')->on('meeting_minutes')
                ->onDelete('cascade');
        });
    }

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