<?php

namespace Modules\User\Services;

use Modules\Auth\Entities\User;

class PublicMemberProfileService
{
    public function findMemberByToken(string $token): ?User
    {
        return User::query()
            ->where('public_profile_token', $token)
            ->where('status', 'active')
            ->first();
    }

    public function loadVerifiableRelations(User $member): User
    {
        $member->load(['employments' => function ($query) {
            $query->orderByDesc('is_current')->orderByDesc('start_date');
        }]);

        return $member;
    }
}
