<?php

declare(strict_types=1);

namespace App\Services\Payment\Providers;

use App\Models\Payment;

class KcpProvider extends AbstractProvider
{
    public function provider(): string
    {
        return 'kcp';
    }

    public function authorize(Payment $payment, array $context = []): array
    {
        if ($this->isMock()) {
            return $this->mockResponse(Payment::STATUS_AUTHORIZED, $payment);
        }
        // Real call: POST https://stg-payment.kcp.co.kr/...
        return $this->mockResponse(Payment::STATUS_AUTHORIZED, $payment, ['raw' => ['note' => 'live-not-implemented']]);
    }

    public function capture(Payment $payment, ?int $amount = null): array
    {
        return $this->mockResponse(Payment::STATUS_CAPTURED, $payment);
    }

    public function refund(Payment $payment, int $amount, ?string $reason = null): array
    {
        return $this->mockResponse(Payment::STATUS_REFUNDED, $payment, ['refund_amount' => $amount]);
    }

    public function getStatus(Payment $payment): array
    {
        return [
            'status' => $payment->status,
            'pg_tid' => $payment->pg_tid,
            'raw' => ['provider' => $this->provider()],
        ];
    }
}
