<?php

namespace FleekDash\Core\Capabilities;

defined('ABSPATH') || exit;

/**
 * ThemeCapabilities
 *
 * Registers and maintains custom capabilities required for theme management.
 */
class ThemeCapabilities
{
    public const MANAGE_FLEEKDASH_THEMES = 'manage_fleekdash_themes';

    /**
     * Bootstrap capability registration.
     */
    public static function register(): void
    {
        \add_action('init', [self::class, 'ensureCapabilities']);
    }

    /**
     * Ensure capabilities are assigned to required roles.
     */
    public static function ensureCapabilities(): void
    {
        $roles = ['administrator'];

        foreach ($roles as $roleName) {
            $role = get_role($roleName);

            if (!$role) {
                continue;
            }

            if (!$role->has_cap(self::MANAGE_FLEEKDASH_THEMES)) {
                $role->add_cap(self::MANAGE_FLEEKDASH_THEMES);
            }
        }
    }
}
