<?php

namespace App\Services\Payments;

use App\Models\PaymentTransaction;

class PaymentTransactionService
{
    public function create(array $payload): PaymentTransaction
    {
        $data = [
            'transaction_id' => $payload['transaction_id'],
            'payment_id' => (int) $payload['payment_id'],
            'transaction_date' => $payload['transaction_date'],
            'amount' => (float) $payload['amount'],
            'payment_method' => $payload['payment_method'],
            'payment_status' => $payload['payment_status'] ?? 'Pending',
            'transaction_fee' => $payload['transaction_fee'] ?? null,
            'payment_reference' => $payload['payment_reference'] ?? null,
            'is_full_payment' => !empty($payload['is_full_payment']),
            'school_year' => $payload['school_year'] ?? null,
            'semester' => $payload['semester'] ?? null,
        ];

        return PaymentTransaction::query()->create($data);
    }

    public function getByPayment(int $paymentId): array
    {
        return PaymentTransaction::getTransactionsByPaymentId($paymentId);
    }

    public function updateStatus(string $transactionId, string $status): bool
    {
        return PaymentTransaction::updateTransactionStatus($transactionId, $status);
    }
}
