<?php

declare(strict_types=1);

namespace App\Dto;

class UsageSummary
{
    public function __construct(
        public readonly LimitCheckResult $users,
        public readonly LimitCheckResult $news,
        public readonly LimitCheckResult $storage,
        public readonly string $licenseStatus,
        public readonly ?int $daysUntilExpiry,
        public readonly string $plan,
    ) {}

    public function hasWarnings(): bool
    {
        return $this->users->isNearLimit()
            || $this->news->isNearLimit()
            || $this->storage->isNearLimit()
            || ($this->daysUntilExpiry !== null && $this->daysUntilExpiry <= 7);
    }

    /**
     * @return string[]
     */
    public function getWarningMessages(): array
    {
        $warnings = [];

        if ($this->users->isNearLimit()) {
            $warnings[] = "Kullanıcı limiti: {$this->users->current}/{$this->users->max} (%{$this->users->percentUsed})";
        }

        if ($this->news->isNearLimit() && $this->news->max > 0) {
            $warnings[] = "Haber limiti: {$this->news->current}/{$this->news->max} (%{$this->news->percentUsed})";
        }

        if ($this->storage->isNearLimit()) {
            $warnings[] = "Depolama limiti: {$this->storage->current}MB / {$this->storage->max}MB (%{$this->storage->percentUsed})";
        }

        if ($this->daysUntilExpiry !== null && $this->daysUntilExpiry <= 7 && $this->daysUntilExpiry > 0) {
            $warnings[] = "Lisansınızın süresi {$this->daysUntilExpiry} gün sonra dolacak.";
        }

        if ($this->daysUntilExpiry !== null && $this->daysUntilExpiry <= 0) {
            $warnings[] = "Lisansınızın süresi dolmuş! Grace period içindesiniz.";
        }

        return $warnings;
    }
}
