<?php

declare(strict_types=1);

namespace App\Models;

class LeadTechnicalProfile extends BaseModel
{
    protected string $table = 'lead_technical_profiles';
    protected string $primaryKey = 'id';

    public function findByLeadId(int $leadId): ?array
    {
        return $this->queryOne(
            "SELECT * FROM {$this->table} WHERE lead_id = :lead_id LIMIT 1",
            ['lead_id' => $leadId]
        );
    }

    public function createOrUpdate(int $leadId, array $data): void
    {
        $existing = $this->findByLeadId($leadId);

        if ($existing) {
            $this->update((int) $existing['id'], $data);
        } else {
            $data['lead_id'] = $leadId;
            $this->create($data);
        }
    }
}
