<?php

namespace Config;

use CodeIgniter\Config\BaseConfig;

class PesaPal extends BaseConfig
{
    /** mm.finflo.net API base (hosts PesaPal proxy endpoints) */
    public string $baseUrl = 'https://mm.finflo.net/public/api';

    /** IPN notification ID registered with PesaPal — required on every order */
    public string $notificationId = 'f6fa4bda-a464-4171-b2ed-da6fa248d3e8';

    public function getBaseUrl(): string
    {
        $v = getenv('PESAPAL_BASE_URL');
        return $v ? rtrim($v, '/') : rtrim($this->baseUrl, '/');
    }

    public function getNotificationId(): string
    {
        return getenv('PESAPAL_NOTIFICATION_ID') ?: $this->notificationId;
    }

    public function getOrderUrl(): string
    {
        return $this->getBaseUrl() . '/pesapal/order';
    }

    /** Uses /transaction/{id} — the endpoint that returns full status from mm.finflo.net DB */
    public function getTransactionUrl(string $trackingId): string
    {
        return $this->getBaseUrl() . '/pesapal/transaction/' . rawurlencode($trackingId);
    }
}
