<?php

namespace App\Http\Controllers\Admin;

use App\Http\Controllers\Controller;
use App\Models\PermissionSetting;
use Illuminate\Http\Request;

class PermissionController extends Controller
{
    public function index()
    {
        $permissions = PermissionSetting::all();
        return view('admin.permissions.index', compact('permissions'));
    }

    public function update(Request $request)
    {
        $permissions = $request->permissions ?? [];

        foreach ($permissions as $key => $value) {
            if (in_array($value, ['free', 'premium'])) {
                PermissionSetting::where('key', $key)->update(['required_membership' => $value]);
            }
        }

        return back()->with('success', 'Global izinler güncellendi.');
    }
}
