<?php

namespace App\Metrics;

use App\Support\Period;
use Mtc\MercuryDataModels\ReportingStat;

class VehicleCount
{
    public function get(Period $period)
    {
        return ReportingStat::query()
            ->where('key', 'vehicle-count')
            ->select(['value', 'date'])
            ->where('date', '>=', $period->startDate->format('Y-m-d'))
            ->where('date', '<=', $period->endDate->format('Y-m-d'))
            ->get()
            ->keyBy(fn ($row) => $row->date->format('Y-m-d'))
            ->map(fn ($row) => $row->value);
    }
}
