<?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
    {
        // Global izin ayarları (tüm site geneli)
        Schema::create('permission_settings', function (Blueprint $table) {
            $table->id();
            $table->string('key')->unique(); // örn: "can_comment", "can_watch", "can_rate"
            $table->string('label');         // Yönetici panelinde görünen ad
            $table->enum('required_membership', ['free', 'premium'])->default('free');
            $table->text('description')->nullable();
            $table->timestamps();
        });

        // İçeriğe özel izin override'ları
        Schema::create('content_permissions', function (Blueprint $table) {
            $table->id();
            $table->string('content_type'); // 'anime', 'episode', 'season'
            $table->unsignedBigInteger('content_id');
            $table->string('permission_key'); // 'can_watch', 'can_comment', vb.
            $table->enum('required_membership', ['free', 'premium']);
            $table->timestamps();

            $table->unique(['content_type', 'content_id', 'permission_key'], 'cp_unique');
            $table->index(['content_type', 'content_id']);
        });
    }

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