<?php

namespace Models;

class TshieldWebhookModel
{
    private \PDO $pdo;

    public function __construct()
    {
        if (!isset($GLOBALS['pdo']) || !($GLOBALS['pdo'] instanceof \PDO)) {
            throw new \RuntimeException('Database connection not initialized.');
        }

        $this->pdo = $GLOBALS['pdo'];
    }

    public function approveByExternalId(string $externalId): bool
    {
        $stmt = $this->pdo->prepare(
            'UPDATE "user" SET user_kyc = 1 WHERE kyc_external_id = :external_id AND user_flag = \'a\''
        );
        $stmt->execute(['external_id' => $externalId]);
        return $stmt->rowCount() > 0;
    }
}
