<?php

namespace App\Modules\Admin\Tenancy\Services;

use App\Modules\Admin\Tenancy\Models\Subscription;
use App\Modules\Admin\Tenancy\Models\Tenant;
use App\Modules\Admin\Tenancy\Repositories\SubscriptionRepository;

class SubscriptionAccessService
{
    public function __construct(
        private readonly SubscriptionRepository $subscriptions,
    ) {}

    public function tenantSubscriptionIsReadOnly(Tenant $tenant): bool
    {
        $latest = $this->subscriptions->latestFor($tenant);
        if ($latest === null) {
            return false;
        }

        return $latest->status === Subscription::STATUS_EXPIRED;
    }
}
