<?php

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

return new class extends Migration
{
    /**
     * Run the migrations.
     */
    public function up(): void
    {
        Schema::create('tailor_specializations', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('icon')->nullable();
            $table->timestamps();
        });

        // Pivot table untuk relasi many-to-many antara penjahit dan spesialisasi
        Schema::create('tailor_specialization_user', function (Blueprint $table) {
            $table->foreignId('user_id')->constrained()->onDelete('cascade');
            $table->foreignId('tailor_specialization_id')->constrained()->onDelete('cascade');
            $table->primary(['user_id', 'tailor_specialization_id']);
        });

        // Insert default specializations
        DB::table('tailor_specializations')->insert([
            ['name' => 'Celana', 'created_at' => now(), 'updated_at' => now()],
            ['name' => 'Rok', 'created_at' => now(), 'updated_at' => now()],
            ['name' => 'Kemeja', 'created_at' => now(), 'updated_at' => now()],
            ['name' => 'Seragam', 'created_at' => now(), 'updated_at' => now()],
            ['name' => 'Jas Blazer', 'created_at' => now(), 'updated_at' => now()],
            ['name' => 'Kebaya', 'created_at' => now(), 'updated_at' => now()],
            ['name' => 'Gaun', 'created_at' => now(), 'updated_at' => now()],
            ['name' => 'Gamis', 'created_at' => now(), 'updated_at' => now()],
        ]);
    }

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