<?php

declare(strict_types=1);

namespace WPStack\Sandbox\WordPress;

use WPStack\Sandbox\Domain\CommunityEntitlement;
use WPStack\Sandbox\Domain\Entitlement;
use WPStack\Sandbox\Premium\ProEntitlement;

final class LicenseManager
{
    public function entitlement(): Entitlement
    {
        $community = new CommunityEntitlement();

        if (!function_exists('wsm_fs')) {
            return $community;
        }

        $freemius = wsm_fs();
        if (
            !is_object($freemius)
            || !$freemius->is__premium_only()
            || !$freemius->can_use_premium_code()
            || !$freemius->is_paying()
            || !class_exists(ProEntitlement::class)
        ) {
            return $community;
        }

        return new ProEntitlement();
    }
}
