<?php

namespace App\Services\Meet;

use App\Models\Member;

class MeetPermissions
{
    /** @var array<string, list<string>> */
    protected array $roleAbilities = [
        'owner' => ['*'],
        'admin' => ['*'],
        'moderator' => [
            'dashboard.view', 'meetings.view', 'meetings.create', 'meetings.manage',
            'meetings.host', 'chat.moderate', 'reports.view', 'settings.view',
        ],
        'member' => [
            'dashboard.view', 'meetings.view', 'meetings.create', 'meetings.host', 'settings.view',
        ],
        'guest' => [
            'meetings.view',
        ],
    ];

    public function can(?Member $member, string $ability): bool
    {
        if ($member === null) {
            return false;
        }

        $abilities = $this->roleAbilities[$member->role] ?? [];

        if (in_array('*', $abilities, true)) {
            return true;
        }

        return in_array($ability, $abilities, true);
    }

    public function isAdmin(?Member $member): bool
    {
        return $member !== null && in_array($member->role, ['owner', 'admin'], true);
    }
}
