<?php

namespace App\Metrics;

use App\Support\Period;
use Illuminate\Support\Facades\DB;
use Mtc\MercuryDataModels\Vehicle;

class VehiclesReserved
{
    public function get(Period $period)
    {
        return Vehicle::query()
            ->withTrashed()
            ->select(DB::raw('count(*) as count'), DB::raw('DATE(reserved_at) as date'))
            ->where('reserved_at', '>=', $period->startDate->format('Y-m-d'))
            ->where('reserved_at', '<=', $period->endDate->format('Y-m-d 23:59:59'))
            ->groupBy('date')
            ->get()
            ->pluck('count', 'date');
    }
}
