<?php

declare(strict_types=1);

final class HyroLeadRepository
{
    public function __construct(
        private readonly PDO $database
    ) {
    }

    public function create(array $lead): int
    {
        $sql = '
            INSERT INTO hyro_leads
            (
                lead_code,
                request_type,
                product_code,
                company_name,
                contact_name,
                email,
                phone,
                country_code,
                country_name,
                city,
                preferred_date,
                preferred_time,
                timezone,
                message,
                source_page,
                source_campaign,
                status,
                assigned_to,
                ip_address,
                user_agent,
                created_at,
                updated_at
            )
            VALUES
            (
                :lead_code,
                :request_type,
                :product_code,
                :company_name,
                :contact_name,
                :email,
                :phone,
                :country_code,
                :country_name,
                :city,
                :preferred_date,
                :preferred_time,
                :timezone,
                :message,
                :source_page,
                :source_campaign,
                :status,
                :assigned_to,
                :ip_address,
                :user_agent,
                :created_at,
                :updated_at
            )
        ';

        $statement = $this->database->prepare($sql);

        $statement->execute([
            'lead_code' => $lead['lead_code'],
            'request_type' => $lead['request_type'],
            'product_code' => $lead['product_code'],
            'company_name' => $lead['company_name'],
            'contact_name' => $lead['contact_name'],
            'email' => $lead['email'],
            'phone' => $lead['phone'],
            'country_code' => $lead['country_code'],
            'country_name' => $lead['country_name'],
            'city' => $lead['city'],
            'preferred_date' => $lead['preferred_date'],
            'preferred_time' => $lead['preferred_time'],
            'timezone' => $lead['timezone'],
            'message' => $lead['message'],
            'source_page' => $lead['source_page'],
            'source_campaign' => $lead['source_campaign'],
            'status' => $lead['status'],
            'assigned_to' => $lead['assigned_to'],
            'ip_address' => $lead['ip_address'],
            'user_agent' => $lead['user_agent'],
            'created_at' => $lead['created_at'],
            'updated_at' => $lead['updated_at'],
        ]);

        return (int) $this->database->lastInsertId();
    }
}
