<?php

namespace App\Http\Controllers\Web;

use App\Services\Response\ResponseService;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use Illuminate\View\View;
use App\Http\Controllers\Controller;
use Modules\Notification\Enums\ManagementNotificationStatusEnum;
use Modules\Notification\Services\ManagementNotificationService;
use Modules\Page\Models\Page;
use Modules\Page\Services\PageService;
use Modules\VisitorMessage\Requests\Web\VisitorMessageRequest;
use Modules\VisitorMessage\Services\VisitorMessageService;


class VisitorMessageController extends Controller
{
    private $view = 'web.pages.contactus.';
    private VisitorMessageService $messageService ;
    private PageService $pageService ;
    private ManagementNotificationService $managementNotificationService ;
    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct(
        VisitorMessageService $messageService, PageService $pageService,ManagementNotificationService $managementNotificationService
    )
    {
        $this->messageService = $messageService;
        $this->pageService = $pageService;
        $this->managementNotificationService = $managementNotificationService;
    }

    /**
     * Show the application dashboard.
     * @return View
     */

    public function index(Request $request): View
    {
        $title = __('web.contactus');
        $action = route('contactus.store');
        $page = Page::findOrFail(7);
        $page = $this->pageService->getItem($page);
        return view($this->view.'contactus', get_defined_vars());
    }


    public function store(VisitorMessageRequest $request) :JsonResponse
    {
        $this->messageService->save($request,null);
        $request->merge(['status'=>ManagementNotificationStatusEnum::CONTACT_US->value]);
        $this->managementNotificationService->create($request);
        $response = [
            'status'=>200,
            'message'=>__('web.success'),
            'data'=> url()->previous(),
        ];
        return ResponseService::response($response);
    }

}
