<?php

namespace App\Repositories\Shop;

use App\Models\Shop\Order;
use App\Repositories\Core\DateStats;
use App\Traits\Model\Basic;

class OrderMetrics
{
    use Basic, DateStats;

    public static function getTotalDaily()
    {
        return self::sumDaily('total_taxed');
    }

    public static function getTotalMonthly()
    {
        return self::sumMonthly('total_taxed');
    }

    public static function countWaiting()
    {
        return Order::waiting()->count();
    }

    public static function countPreparationLess24h()
    {
        $date = now()->subHours(24);

        return Order::Preparation()->where('updated_at', '>', $date)->count();
    }

    public static function countPreparationLess48h()
    {
        $date = now()->subHours(48);

        return Order::Preparation()->where('updated_at', '>', $date)->count();
    }

    public static function countPreparationMore48h()
    {
        $date = now()->subHours(48);

        return Order::Preparation()->where('updated_at', '<', $date)->count();
    }

    public static function countOfToday()
    {
        return Order::notCancelled()->ofToday()->count();
    }

    public static function countOfLastWeek()
    {
        return Order::notCancelled()->ofLastWeek()->count();
    }

    public static function countOfLastMonth()
    {
        return Order::notCancelled()->ofLastMonth()->count();
    }

    public static function getTotalOfToday()
    {
        return Order::notCancelled()->ofToday()->sum('total_taxed');
    }

    public static function getTotalOfLastWeek()
    {
        return Order::notCancelled()->ofLastWeek()->sum('total_taxed');
    }

    public static function getTotalOfLastMonth()
    {
        return Order::notCancelled()->ofLastMonth()->sum('total_taxed');
    }

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