<?php

namespace App\Services\Payments;

class MpesaGateway implements PaymentGatewayInterface
{
    private \Config\TibaLeta $config;
    public function __construct(){ $this->config=config('TibaLeta'); }
    private function configured(): bool { return $this->config->mpesaConsumerKey!=='' && $this->config->mpesaConsumerSecret!=='' && $this->config->mpesaShortcode!=='' && $this->config->mpesaPasskey!==''; }
    public function initiate(array $payment,array $customer): array
    {
        if(!$this->configured()) return ['status'=>'configuration_required','message'=>'M-Pesa credentials are not configured.','reference'=>$payment['reference'] ?? null];
        // Connect Daraja/STK adapter here. Domain payment records remain provider-agnostic.
        return ['status'=>'pending','reference'=>$payment['reference'] ?? null];
    }
    public function verify(string $reference): array { return ['status'=>$this->configured()?'pending':'configuration_required','reference'=>$reference]; }
    public function refund(string $reference,float $amount): array { return ['status'=>$this->configured()?'pending':'configuration_required','reference'=>$reference,'amount'=>$amount]; }
}
