<?php

namespace Gaco\SnapBi\Tests\Unit;

use Gaco\SnapBi\Tests\TestCase;
use Gaco\SnapBi\Services\VirtualAccountService;
use Gaco\SnapBi\Enums\ServiceCode;

class VirtualAccountServiceTest extends TestCase
{
    public function test_virtual_account_service_with_inquiry_code()
    {
        $service = new VirtualAccountService(ServiceCode::INQUIRY);
        $response = $service->response()->success([
            'virtualAccountData' => [
                'virtualAccountNo' => '123456789'
            ]
        ]);

        $this->assertEquals(200, $response->getStatusCode());
        $data = json_decode($response->getContent(), true);
        $this->assertEquals('2002400', $data['responseCode']);
    }

    public function test_virtual_account_service_with_payment_code()
    {
        $service = new VirtualAccountService(ServiceCode::PAYMENT);
        $response = $service->response()->success([
            'virtualAccountData' => [
                'virtualAccountNo' => '123456789'
            ]
        ]);

        $this->assertEquals(200, $response->getStatusCode());
        $data = json_decode($response->getContent(), true);
        $this->assertEquals('2002500', $data['responseCode']);
    }

    public function test_virtual_account_service_with_transfer_code()
    {
        $service = new VirtualAccountService(ServiceCode::TRANSFER_INQUIRY);
        $response = $service->response()->success([
            'virtualAccountData' => [
                'virtualAccountNo' => '123456789'
            ]
        ]);

        $this->assertEquals(200, $response->getStatusCode());
        $data = json_decode($response->getContent(), true);
        $this->assertEquals('2003200', $data['responseCode']);
    }

    public function test_virtual_account_service_with_update_status_code()
    {
        $service = new VirtualAccountService(ServiceCode::UPDATE_STATUS_VA);
        $response = $service->response()->success([
            'virtualAccountData' => [
                'virtualAccountNo' => '123456789'
            ]
        ]);

        $this->assertEquals(200, $response->getStatusCode());
        $data = json_decode($response->getContent(), true);
        $this->assertEquals('2002900', $data['responseCode']);
    }

    public function test_virtual_account_service_with_inquiry_status_code()
    {
        $service = new VirtualAccountService(ServiceCode::INQUIRY_STATUS);
        $response = $service->response()->success([
            'virtualAccountData' => [
                'virtualAccountNo' => '123456789'
            ]
        ]);

        $this->assertEquals(200, $response->getStatusCode());
        $data = json_decode($response->getContent(), true);
        $this->assertEquals('2002600', $data['responseCode']);
    }

    public function test_virtual_account_service_with_notify_payment_code()
    {
        $service = new VirtualAccountService(ServiceCode::NOTIF_PAYMENT_INTRABANK);
        $response = $service->response()->success([
            'virtualAccountData' => [
                'virtualAccountNo' => '123456789'
            ]
        ]);

        $this->assertEquals(200, $response->getStatusCode());
        $data = json_decode($response->getContent(), true);
        $this->assertEquals('2003400', $data['responseCode']);
    }

    public function test_virtual_account_service_error_response()
    {
        $service = new VirtualAccountService(ServiceCode::INQUIRY);
        $response = $service->response()->error([
            'httpCode' => 404,
            'caseCode' => 12,
            'message' => 'Invalid Bill/Virtual Account'
        ]);

        $this->assertEquals(404, $response->getStatusCode());
        $data = json_decode($response->getContent(), true);
        $this->assertEquals('4042412', $data['responseCode']);
        $this->assertEquals('Invalid Bill/Virtual Account', $data['responseMessage']);
    }
}

