<?php


namespace App\Classes\Modules\Transactions\ControllersLogic;

use App\Classes\General\Abstracts\AbstractControllerLogic;
use App\Classes\Modules\Transactions\Services\FetchesTransaction;
use App\Classes\ValueObjects\Constants\PaymentMethodType;
use App\Http\Resources\TransactionResource;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
use App\Classes\Modules\Transactions\Processors\CreatePaymentTransactionProcessor;

class CreatePaymentTransactionLogic extends AbstractControllerLogic
{

    /**
     * @return array
     */
    protected function notification():array {
        return [
            'title' => 'Create Payment Transactions',
            'message' => 'You have successfully created currency supplier transactions'
        ];
    }

    /** @var FetchesTransaction */
    private $fetchesTransaction;

    /** @var CreatePaymentTransactionProcessor */
    private $createPaymentTransactionProcessor;

    public function __construct(
        FetchesTransaction $fetchesTransaction,
        CreatePaymentTransactionProcessor $createPaymentTransactionProcessor
    )
    {
        $this->fetchesTransaction = $fetchesTransaction;
        $this->createPaymentTransactionProcessor = $createPaymentTransactionProcessor;
    }

    public function logic(Request $request) : JsonResponse
    {
        $payment_method = PaymentMethodType::PAYMENT_METHODS[$request->input('payment_method')];

        $invoice_transaction = $this->fetchesTransaction->execute(['id' => $request->input('transaction_id')]);

        $payment_transaction = $this->createPaymentTransactionProcessor->execute($invoice_transaction, $payment_method , $request->input('bank_code'));

        //cief todo: at exchange there is a transition step - starts
        // if(PaymentMethodType::PAYMENT_METHODS[$request->input('payment_method')] == PaymentMethodType::PAYMENT_GATEWAY){
        //     $this->updatesTransactionStatus->execute($transaction, ApprovalStatus::PENDING_VERIFICATION);
        // }

        // if(config('perfexcrm.is_enabled') == 'true'){
        //     $this->transactionToPerfexCRMV2Processor->execute($transaction, $status);
        // }

        //To use
        //ApprovalStatus::PENDING_VERIFICATION;
        //use this to trigger  $this->transactionToPerfexCRMV2Processor->execute > defineTasks > defineTasks_handlePendingVerificationStatus > definePaymentTasks
        //cief todo: at exchange there is a transition step - ends

        return $this->resourceResponse(new TransactionResource($payment_transaction));
    }
}
