<?php

namespace App\Classes\Modules\ControllersLogic\Dashboard;

use App\Models\Order;

class OrdersStatusReportLogic
{
    /* @var Order */
    private $repository;

    /**
     * OrderTypeReportLogic constructor.
     * @param Order $repository
     */
    public function __construct(Order $repository)
    {
        $this->repository = $repository;
    }

    public function execute() {
        $status = $this->repository->whereNotNull('current_step')->get()->groupBy('current_step');
        $completed = $this->repository->whereNull('current_step')->where('complete', '=' , 1)->get();

        $statusMap = $status->map(function ($item) {
            return collect($item)->count();
        })->toArray();

        $completedArray = ["COMPLETED" => $completed->count()];
        $combine = $statusMap + $completedArray;
        return [
            (isset($combine['PS_PROCESSING'])) ? $combine['PS_PROCESSING'] : 0,
            (isset($combine['MS_WAREHOUSE_RECEIVING'])) ? $combine['MS_WAREHOUSE_RECEIVING'] : 0,
            (isset($combine['PS_SHIPPING'])) ? $combine['PS_SHIPPING'] : 0,
            (isset($combine['COMPLETED'])) ? $combine['COMPLETED'] : 0
        ];
    }
}