<?php

namespace App\Services;

use App\Models\PlayerProfile;

class ProfileCompletionService
{
    /**
     * @return int Percentage from 0 to 100.
     */
    public function calculate(PlayerProfile $profile): int
    {
        $profile->loadCount(['socialLinks', 'languages', 'gameProfiles']);

        $checks = [
            filled($profile->display_name),
            filled($profile->bio),
            filled($profile->avatar_path),
            filled($profile->cover_path),
            filled($profile->country_code),
            filled($profile->city),
            filled($profile->birth_date),
            $profile->social_links_count > 0,
            $profile->languages_count > 0,
            $profile->game_profiles_count > 0,
        ];

        $filled = count(array_filter($checks));
        $total = count($checks);

        return (int) round(($filled / $total) * 100);
    }
}
