<?php

namespace App\Modules\CardOrder\Repositories;

use App\Modules\CardOrder\Models\CardOrder;
use App\Modules\HalkbankOnlinePayment\Repositories\HalkbankOnlinePaymentRepository;
use App\Modules\Makeable;
use App\Modules\OnlinePayment\Repositories\OnlinePaymentRepository;

class CardOrderRepository
{
    use Makeable;

    /**
     * Create online payment order
     */
    public function createOnlinePaymentOrder(CardOrder $record): OnlinePaymentRepository
    {
        /** @var \App\Modules\Branch\Models\Branch */
        $branch = $record->branch;

        return OnlinePaymentRepository::make(relatedModel: $record)
            ->paymentProvider(
                HalkbankOnlinePaymentRepository::make()
                    ->setUsername($branch->billingUsername())
                    ->setPassword($branch->billingPassword())
                    ->setAmount($record->priceAmount())
                    ->setReturnUrl(route('halkbank-online-payment.store'))
                    ->setDescription('Kart tölegi')
            )
            ->sendRequest();
    }
}
