<?php

declare(strict_types=1);

namespace App\Services;

use App\Enums\AccountType;
use App\Enums\ProfessionalVerificationStatus;
use App\Models\ProfessionalProfile;
use App\Models\User;

final class ProfessionalProfileCounter
{
    public static function increment(int $userId, string $column): void
    {
        if (! in_array($column, ['total_requests', 'total_proposals', 'total_closed_deals'], true)) {
            return;
        }

        $user = User::query()->find($userId);
        if ($user === null) {
            return;
        }

        $accountTypeValue = $user->account_type?->value ?? AccountType::IndependentAgent->value;

        $profile = ProfessionalProfile::query()->firstOrCreate(
            ['user_id' => $user->id],
            [
                'professional_name' => $user->name,
                'profile_type' => $accountTypeValue,
                'logo_or_photo' => null,
                'city_id' => null,
                'bio' => null,
                'phone_visible' => false,
                'email_visible' => false,
                'verification_status' => ProfessionalVerificationStatus::Pending,
            ],
        );

        $profile->increment($column);
    }
}
