<?php

namespace Modules\Notification\Services;

use Illuminate\Http\Request;
use Modules\Notification\Enums\ManagementNotificationStatusEnum;
use Modules\Notification\Interfaces\ManagementNotificationRepositoryInterface;
use Modules\Notification\Interfaces\NotificationRepositoryInterface;
use Modules\Notification\Models\ManagementNotification;
use Modules\Notification\Models\Notification;
use Modules\Order\Enums\OrderStatusEnum;
use Modules\User\Services\UserService;

class ManagementNotificationService
{
    private ManagementNotificationRepositoryInterface $managementNotificationRepository ;

    public function __construct(ManagementNotificationRepositoryInterface $managementNotificationRepository)
    {
        $this->managementNotificationRepository = $managementNotificationRepository;
    }

    public function get(Request $request)
    {
        $notifications = $this->managementNotificationRepository->get($request);
        return $notifications;
    }

    public function save(Request $request, ?ManagementNotification $managementNotification): void
    {
        $this->managementNotificationRepository->save($request,$managementNotification);

    }

    public function create(Request $request)
    {
        $status = $request->status;
        switch ($request->status)
        {
            case ManagementNotificationStatusEnum::NEW_ORDER->value :
                $title_ar = 'تم انشاء طلب جديد برقم ' . $request['order_id'];
                $title_en = 'New order had been created with No. ' . $request['order_id'];
                $description_ar = 'تم انشاء طلب جديد برقم ' . $request['order_id'];
                $description_en = 'New order had been created with No. ' . $request['order_id'];
                break;
            case ManagementNotificationStatusEnum::PRODUCT_EMPTY->value :
                $title_ar = 'المنتج رقم : '.($request['product_id']) . ' اوشك علي النفاذ' ;
                $title_en = 'Product No : ' . ($request['product_id']) . ' is close to finish';
                $description_ar =  'المنتج رقم : '.($request['product_id']) . ' اوشك علي النفاذ' ;
                $description_en = 'Product No : ' . ($request['product_id']) . ' is close to finish';
                break;
            default:
                $title_ar = 'تم انشاء نموذج اتصل بنا جديد ' ;
                $title_en = 'New Visitor Message received ' ;
                $description_ar = 'تم انشاء طلب جديد برقم ' ;
                $description_en = 'تم انشاء نموذج اتصل بنا جديد ';

        }
        $request->merge(['status'=>$status,'title_ar'=>$title_ar,'title_en'=>$title_en,'description_ar'=>$description_ar,'description_en'=>$description_en]);

        $this->save($request,null);
    }

}
