<?php

namespace App\Http\Controllers\Employee;

use App\Http\Controllers\Controller;
use App\Http\Requests\Employee\EmailUpdateRequest;
use App\Http\Requests\Employee\PasswordUpdateRequest;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Illuminate\View\View;

class SettingController extends Controller
{
    public function index(Request $request): View
    {
        $user = $request->user();

        return view('employee.pages.profile.setting', compact('user'));
    }

    public function updateEmail(EmailUpdateRequest $request): RedirectResponse
    {
        $request->user()->update([
            'email' => $request->email,
        ]);

        return redirect()->route('employee.profile.account')->with('success', 'Email updated successfully!');
    }

    public function updatePassword(PasswordUpdateRequest $request): RedirectResponse
    {
        $request->user()->update([
            'password' => Hash::make($request->password),
        ]);

        return redirect()->route('employee.profile.account')->with('success', 'Password updated successfuly!');
    }
}
