<?php

namespace App\Services\Concerns;

use App\Models\Employee;
use App\Models\User;
use Illuminate\Validation\ValidationException;

trait ResolvesAuthenticatedEmployee
{
    private function resolveAuthenticatedEmployee(?User $user = null): Employee
    {
        $employee = ($user ?? auth()->user())?->employee;

        if ($employee === null) {
            throw ValidationException::withMessages([
                'employee' => 'Akun Anda tidak terhubung ke data pegawai.',
            ]);
        }

        return $employee;
    }
}
