<?php

namespace App\Http\Controllers;

use App\Enums\OrderStatusEnum;
use App\Enums\OrderType;
use App\Models\OrderArchive;
use Carbon\Carbon;

class SupplierFeedbackController extends Controller
{
    public function orderFeedback($orderFeedbackId)
    {
        if ($Order = OrderArchive::where('feedBackId', base64_decode($orderFeedbackId))->get()->first()) {
            $viewData = $Order->toArray();
            if (! is_null($Order->confirmed)) {
                $viewData['confirmedBefore'] = true;

                return view('modules.order.supplierFeedback')->with($viewData);
            }
            if ($Order->orderType == OrderType::weekly) {
                foreach ($Order->children as $dayOrder) {
                    $dayOrder->confirmed = Carbon::now();
                    // $dayOrder->orderStatus=OrderStatusEnum::confirmed;
                    $dayOrder->save();

                }
            }
            $Order->confirmed = Carbon::now();
            // $Order->orderStatus=OrderStatusEnum::confirmed;
            $Order->save();
            $viewData = $Order->toArray();

            return view('modules.order.supplierFeedback')->with($viewData);

        }

        return response(null, 500);

    }
}
