<?php

namespace App\Repositories\Shop;

use App\Models\Shop\Order;
use App\Repositories\Core\DateStats;
use Carbon\Carbon;

class OrderMetrics
{
    use DateStats;

    public static function countInPreparationLess24H()
    {
        $start = Carbon::now()->subHours(24);
        $end = Carbon::now();

        return Order::preparation()->byPeriod($start, $end, 'updated_at')->count();
    }

    public static function countInPreparationLess48H()
    {
        $start = Carbon::now()->subHours(48);
        $end = Carbon::now();

        return Order::preparation()->byPeriod($start, $end, 'updated_at')->count();
    }

    public static function countInPreparationMore48H()
    {
        $start = Carbon::now()->subHours(48);

        return Order::preparation()->where('updated_at', '>', $start)->count();
    }

    public static function getTotalByPeriod($start, $end)
    {
        return self::sumByPeriod($start, $end, 'total_shipped');
    }

    public static function getModel()
    {
        return Order::query();
    }
}
