<?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('store_user', function (Blueprint $table) {
            $table->id();
            // ID Toko di Teratory
            $table->foreignId('store_id')->constrained('stores')->cascadeOnDelete();
            
            // ID User dari Bitter ID (bukan foreign key karena beda database)
            $table->unsignedBigInteger('user_id'); 
            
            // Hak Akses mutlak
            $table->enum('role', ['owner', 'qa', 'manager', 'barista', 'kitchen']);
            
            $table->timestamps();

            // Mencegah 1 orang punya 2 jabatan ganda di 1 toko yang sama
            $table->unique(['store_id', 'user_id']);
        });
    }

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