<?php

namespace App\Notifications;

use App\Models\Company;

class SubscriptionExpiringNotification extends HrmsNotification
{
    public function __construct(
        protected Company $company,
        protected int $daysRemaining,
        protected bool $suspended = false
    ) {}

    public function notificationCategory(): string
    {
        return 'subscription';
    }

    public function notificationSubject(): string
    {
        if ($this->suspended) {
            return 'Subscription suspended — renew to restore access';
        }

        if ($this->daysRemaining < 0) {
            return 'Subscription expired';
        }

        if ($this->daysRemaining === 0) {
            return 'Subscription expires today';
        }

        return 'Subscription expires in '.$this->daysRemaining.' day'.($this->daysRemaining === 1 ? '' : 's');
    }

    public function notificationLines(): array
    {
        $plan = $this->company->subscriptionPlan?->name ?? 'your plan';
        $date = $this->company->licence_expire_on?->format('d M Y') ?? '—';

        if ($this->suspended) {
            return [
                'Your KiyoHR subscription for '.$plan.' has been suspended because the licence expired on '.$date.'.',
                'Renew your plan to restore full access.',
            ];
        }

        return [
            'Your licence for '.$plan.' expires on '.$date.'.',
            'Renew or upgrade from the Subscription page to avoid interruption.',
        ];
    }

    public function actionUrl(): ?string
    {
        return route('subscription.request');
    }

    public function actionLabel(): string
    {
        return 'Manage subscription';
    }
}
