<?php

namespace App\Http\Controllers\Web;

use App\Http\Controllers\Controller;
use App\Services\Response\ResponseService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\View\View;
use Modules\Notification\Services\NotificationService;
use Modules\Order\Enums\OrderStatusEnum;
use Modules\User\Models\User;
use Modules\User\Requests\Web\ProfileRequest;
use Modules\User\Services\UserService;

class ProfileController extends Controller
{
    private $view = 'web.pages.profile.';
    private UserService $userService ;
    private NotificationService $notificationService ;


    public function __construct(
        UserService $userService,
        NotificationService $notificationService,
    )
    {
        $this->userService = $userService;
        $this->notificationService = $notificationService;
    }

    public function profile(Request $request) :View
    {
        $title = __('web.profile');
        $user = Auth::user();
        $action = route('web.profile.edit');
        $order_statuses = OrderStatusEnum::values();
        return view($this->view.'profile',get_defined_vars());
    }

    public function editProfile(ProfileRequest $request) :JsonResponse
    {
        if (!$request->password)
        {
            $request->request->remove('password');
        }
        $this->userService->save($request,Auth::user());

        $response = [
            'status' => 200,
            'message' => __('web.success'),
            'data' => route('web.profile')
        ];
        return ResponseService::response($response);
    }

    public function notification(Request $request)
    {
        $title = __('web.notifications');
        $request->merge(['user_id'=>Auth::user()->id]);
        $notifications = $this->notificationService->get($request);
        return view($this->view.'notifications',get_defined_vars());
    }

    public function notificationDelete(Request $request)
    {
        $request->merge(['user_id'=>Auth::user()->id]);
        $this->notificationService->deleteAllUser($request);
        return redirect(route('web.profile'));
    }

}
