<?php

namespace App\Nova\Resources\Order\Loan\Metrics;

use App\Models\Order\Loan\LoanOrder;
use App\Repos\Order\OrderRepo;
use Laravel\Nova\Http\Requests\NovaRequest;
use Laravel\Nova\Metrics\Partition;

class LoanOrderPerStatus extends Partition
{
    /**
     * Get the displayable name of the metric
     */
    public function name(): string
    {
        return sprintf('%s (%s)', __('Loan orders'), __('all'));
    }

    /**
     * Calculate the value of the metric.
     */
    public function calculate(NovaRequest $request): mixed
    {
        return $this->count($request, LoanOrder::class, 'status')
            ->colors(OrderRepo::statusColors())
            ->label(fn ($value) => match ($value) {
                null => __('None'),
                default => OrderRepo::statusFormatted($value)
            });
    }

    /**
     * Determine the amount of time the results of the metric should be cached.
     *
     * @return \DateTimeInterface|\DateInterval|float|int|null
     */
    public function cacheFor()
    {
        // return now()->addMinutes(5);
    }

    /**
     * Get the URI key for the metric.
     */
    public function uriKey(): string
    {
        return 'loan-order-per-status';
    }
}
