<?php

namespace App\Classes\Modules\Transactions\Processors;

use App\Classes\Modules\Wallets\DataTransferObjects\WalletObject;
use App\Classes\Modules\Transactions\Services\CreatesWalletTransaction;
use App\Classes\Modules\Transactions\Services\GeneratesTransactionBillNumber;
use App\Classes\Modules\Transactions\DataTransferObjects\TransactionObject;
use App\Classes\ValueObjects\Constants\ApprovalStatus;
use App\Classes\ValueObjects\Constants\SegmentConstants;
use App\Classes\ValueObjects\Constants\TransactionType;
use App\Classes\ValueObjects\Constants\PaymentMethodType;
use App\Models\Wallet;

class CreateWalletTransactionProcessor
{
    /** @var CreatesWalletTransaction */
    private $createsWalletTransaction;

    /** @var GeneratesTransactionBillNumber */
    private $generatesTransactionBillNumber;

    public function __construct(CreatesWalletTransaction $createsWalletTransaction, GeneratesTransactionBillNumber $generatesTransactionBillNumber)
    {
        $this->generatesTransactionBillNumber = $generatesTransactionBillNumber;
        $this->createsWalletTransaction = $createsWalletTransaction;
    }


    /**
     * @param Booking $booking
     * @return void
     * @throws \App\Classes\Exceptions\MalformedRequestException
     */
    public function execute(Wallet $wallet, WalletObject $walletOject, int $transactionType)
    {

        $billNumber = $this->generatesTransactionBillNumber->execute('WAL-');

        $transaction_object = new TransactionObject(
            $billNumber,
            $transactionType,
            $wallet->company->id,
            1,
            1,
            PaymentMethodType::BA,
            $walletOject->getAmount(),
            $walletOject->getAmount(),
            $wallet->currency_id,
            $wallet->currency_id,
            0,
            0,
            0,
            null,
            ApprovalStatus::PENDING_SUBMISSION
        );
        $walletTransaction = $this->createsWalletTransaction->execute($wallet, $transaction_object);

        return $walletTransaction;
    }
}
