<?php

declare(strict_types=1);

namespace KHQR\Tests;

use KHQR\BakongKHQR;
use PHPUnit\Framework\TestCase;

class DecodeTest extends TestCase
{
    private $testData = [
        [
            'statement' => 'Decode Test 1',
            'data' => '00020101021229190015john_smith@devb52045999530311654065000.05802KH5910jonh smith6010Phnom Penh62360109#INV-20030313Coffee Klaing0702#299170013161302797275763049ACF',
            'result' => [
                'merchantType' => '29',
                'bakongAccountID' => 'john_smith@devb',
                'accountInformation' => null,
                'merchantID' => null,
                'acquiringBank' => null,
                'billNumber' => '#INV-2003',
                'mobileNumber' => null,
                'storeLabel' => 'Coffee Klaing',
                'terminalLabel' => '#2',
                'purposeOfTransaction' => null,
                'languagePreference' => null,
                'merchantNameAlternateLanguage' => null,
                'merchantCityAlternateLanguage' => null,
                'creationTimestamp' => '1613027972757',
                'expirationTimestamp' => null,
                'payloadFormatIndicator' => '01',
                'pointofInitiationMethod' => '12',
                'unionPayMerchant' => null,
                'merchantCategoryCode' => '5999',
                'transactionCurrency' => '116',
                'transactionAmount' => '5000.0',
                'countryCode' => 'KH',
                'merchantName' => 'jonh smith',
                'merchantCity' => 'Phnom Penh',
                'crc' => '9ACF',
            ],
        ],
        [
            'statement' => 'Decode Test 2',
            'data' => '00020101021230410015john_smith@devb01061234560208Dev Bank52045999530384054035.05802KH5916john smith actor6010Phnom Penh62130709Counter 299170013161343857579463048EF2',
            'result' => [
                'merchantType' => '30',
                'bakongAccountID' => 'john_smith@devb',
                'accountInformation' => null,
                'merchantID' => '123456',
                'acquiringBank' => 'Dev Bank',
                'billNumber' => null,
                'mobileNumber' => null,
                'storeLabel' => null,
                'terminalLabel' => 'Counter 2',
                'purposeOfTransaction' => null,
                'languagePreference' => null,
                'merchantNameAlternateLanguage' => null,
                'merchantCityAlternateLanguage' => null,
                'creationTimestamp' => '1613438575794',
                'expirationTimestamp' => null,
                'payloadFormatIndicator' => '01',
                'pointofInitiationMethod' => '12',
                'unionPayMerchant' => null,
                'merchantCategoryCode' => '5999',
                'transactionCurrency' => '840',
                'transactionAmount' => '5.0',
                'countryCode' => 'KH',
                'merchantName' => 'john smith actor',
                'merchantCity' => 'Phnom Penh',
                'crc' => '8EF2',
            ],
        ],
        [
            'statement' => 'Decode Test 3',
            'data' => '00020101021230410015john_smith@devb01061234560208Dev Bank52045999530384054035.05802KH5916john smith actor6010Phnom Penh62280111Invoice#0690709Counter 29917001316134385758926304384E',
            'result' => [
                'merchantType' => '30',
                'bakongAccountID' => 'john_smith@devb',
                'accountInformation' => null,
                'merchantID' => '123456',
                'acquiringBank' => 'Dev Bank',
                'billNumber' => 'Invoice#069',
                'mobileNumber' => null,
                'storeLabel' => null,
                'terminalLabel' => 'Counter 2',
                'purposeOfTransaction' => null,
                'languagePreference' => null,
                'merchantNameAlternateLanguage' => null,
                'merchantCityAlternateLanguage' => null,
                'creationTimestamp' => '1613438575892',
                'expirationTimestamp' => null,
                'payloadFormatIndicator' => '01',
                'pointofInitiationMethod' => '12',
                'unionPayMerchant' => null,
                'merchantCategoryCode' => '5999',
                'transactionCurrency' => '840',
                'transactionAmount' => '5.0',
                'countryCode' => 'KH',
                'merchantName' => 'john smith actor',
                'merchantCity' => 'Phnom Penh',
                'crc' => '384E',
            ],
        ],
        [
            'statement' => 'Decode Test 4',
            'data' => '00020101021230410015john_smith@devb01061234560208Dev Bank52045999530384054035.05802KH5916john smith actor6010Phnom Penh62150111Invoice#0699917001316134385758926304552D',
            'result' => [
                'merchantType' => '30',
                'bakongAccountID' => 'john_smith@devb',
                'accountInformation' => null,
                'merchantID' => '123456',
                'acquiringBank' => 'Dev Bank',
                'billNumber' => 'Invoice#069',
                'mobileNumber' => null,
                'storeLabel' => null,
                'terminalLabel' => null,
                'purposeOfTransaction' => null,
                'languagePreference' => null,
                'merchantNameAlternateLanguage' => null,
                'merchantCityAlternateLanguage' => null,
                'creationTimestamp' => '1613438575892',
                'expirationTimestamp' => null,
                'payloadFormatIndicator' => '01',
                'pointofInitiationMethod' => '12',
                'unionPayMerchant' => null,
                'merchantCategoryCode' => '5999',
                'transactionCurrency' => '840',
                'transactionAmount' => '5.0',
                'countryCode' => 'KH',
                'merchantName' => 'john smith actor',
                'merchantCity' => 'Phnom Penh',
                'crc' => '552D',
            ],
        ],
        [
            'statement' => 'Decode Test 5',
            'data' => '000201010211021641277800000000980416518352888000006030470016abaakhppxxx@abaa01153166007701102420204abaa5204224253038405802KH5910USD OUTLET6010PHNOM PENH62250509115B02750070827CE19809924001339CA026411FDA6803mmp63043870',
            'result' => [
                'merchantType' => '30',
                'bakongAccountID' => 'abaakhppxxx@abaa',
                'accountInformation' => null,
                'merchantID' => '316600770110242',
                'acquiringBank' => 'abaa',
                'billNumber' => null,
                'mobileNumber' => null,
                'storeLabel' => null,
                'terminalLabel' => '27CE1980',
                'purposeOfTransaction' => null,
                'languagePreference' => null,
                'merchantNameAlternateLanguage' => null,
                'merchantCityAlternateLanguage' => null,
                'creationTimestamp' => '39CA026411FDA',
                'expirationTimestamp' => null,
                'payloadFormatIndicator' => '01',
                'pointofInitiationMethod' => '11',
                'unionPayMerchant' => null,
                'merchantCategoryCode' => '2242',
                'transactionCurrency' => '840',
                'transactionAmount' => null,
                'countryCode' => 'KH',
                'merchantName' => 'USD OUTLET',
                'merchantCity' => 'PHNOM PENH',
                'crc' => '3870',
            ],
        ],
        [
            'statement' => 'Decode Test 6',
            'data' => '00020101021130470009khqr@aclb0111855124649170215ACLEDA Bank Plc5204599953038405802KH5907BUN MAO6010Phnom Penh6102126213020901050033164310002KM0107BUN MAO0210Phnom Penh6304E313',
            'result' => [
                'merchantType' => '30',
                'bakongAccountID' => 'khqr@aclb',
                'accountInformation' => null,
                'merchantID' => '85512464917',
                'acquiringBank' => 'ACLEDA Bank Plc',
                'billNumber' => null,
                'mobileNumber' => '010500331',
                'storeLabel' => null,
                'terminalLabel' => null,
                'purposeOfTransaction' => null,
                'languagePreference' => 'KM',
                'merchantNameAlternateLanguage' => 'BUN MAO',
                'merchantCityAlternateLanguage' => 'Phnom Penh',
                'creationTimestamp' => null,
                'expirationTimestamp' => null,
                'payloadFormatIndicator' => '01',
                'pointofInitiationMethod' => '11',
                'unionPayMerchant' => null,
                'merchantCategoryCode' => '5999',
                'transactionCurrency' => '840',
                'transactionAmount' => null,
                'countryCode' => 'KH',
                'merchantName' => 'BUN MAO',
                'merchantCity' => 'Phnom Penh',
                'crc' => 'E313',
            ],
        ],
        [
            'statement' => 'Decode Test 7',
            'data' => '00020101021130640009khqr@aclb0111855124649060215ACLEDA Bank Plc051385500000019425204593153038405802KH5912KHQR TESTING6010Phnom Penh6102126213020901753577164360002KM0112KHQR TESTING0210Phnom Penh6304AC1C',
            'result' => [
                'merchantType' => '30',
                'bakongAccountID' => 'khqr@aclb',
                'accountInformation' => null,
                'merchantID' => '85512464906',
                'acquiringBank' => 'ACLEDA Bank Plc',
                'billNumber' => null,
                'mobileNumber' => '017535771',
                'storeLabel' => null,
                'terminalLabel' => null,
                'purposeOfTransaction' => null,
                'languagePreference' => 'KM',
                'merchantNameAlternateLanguage' => 'KHQR TESTING',
                'merchantCityAlternateLanguage' => 'Phnom Penh',
                'creationTimestamp' => null,
                'expirationTimestamp' => null,
                'payloadFormatIndicator' => '01',
                'pointofInitiationMethod' => '11',
                'unionPayMerchant' => null,
                'merchantCategoryCode' => '5931',
                'transactionCurrency' => '840',
                'transactionAmount' => null,
                'countryCode' => 'KH',
                'merchantName' => 'KHQR TESTING',
                'merchantCity' => 'Phnom Penh',
                'crc' => 'AC1C',
            ],
        ],
        [
            'statement' => 'Decode Test 8',
            'data' => '00020101021229310014jonhsmith@nbcq0109012345678520459995303116540750000.05802KH5910Jonh Smith6009Siam Reap62550117INV-2021-07-658220211855123456780305BKK-1070601234599170013163039583850263041134',
            'result' => [
                'merchantType' => '29',
                'bakongAccountID' => 'jonhsmith@nbcq',
                'accountInformation' => '012345678',
                'merchantID' => null,
                'acquiringBank' => null,
                'billNumber' => 'INV-2021-07-65822',
                'mobileNumber' => '85512345678',
                'storeLabel' => 'BKK-1',
                'terminalLabel' => '012345',
                'purposeOfTransaction' => null,
                'languagePreference' => null,
                'merchantNameAlternateLanguage' => null,
                'merchantCityAlternateLanguage' => null,
                'creationTimestamp' => '1630395838502',
                'expirationTimestamp' => null,
                'payloadFormatIndicator' => '01',
                'pointofInitiationMethod' => '12',
                'unionPayMerchant' => null,
                'merchantCategoryCode' => '5999',
                'transactionCurrency' => '116',
                'transactionAmount' => '50000.0',
                'countryCode' => 'KH',
                'merchantName' => 'Jonh Smith',
                'merchantCity' => 'Siam Reap',
                'crc' => '1134',
            ],
        ],
        [
            'statement' => 'Decode Test 9',
            'data' => 'EAB3',
            'result' => [
                'merchantType' => null,
                'bakongAccountID' => null,
                'accountInformation' => null,
                'merchantID' => null,
                'acquiringBank' => null,
                'billNumber' => null,
                'mobileNumber' => null,
                'storeLabel' => null,
                'terminalLabel' => null,
                'purposeOfTransaction' => null,
                'languagePreference' => null,
                'merchantNameAlternateLanguage' => null,
                'merchantCityAlternateLanguage' => null,
                'creationTimestamp' => null,
                'expirationTimestamp' => null,
                'payloadFormatIndicator' => null,
                'pointofInitiationMethod' => null,
                'unionPayMerchant' => null,
                'merchantCategoryCode' => null,
                'transactionCurrency' => null,
                'transactionAmount' => null,
                'countryCode' => null,
                'merchantName' => null,
                'merchantCity' => null,
                'crc' => null,
            ],
        ],
        [
            'statement' => 'Decode Test 10',
            'data' => '00020101021230190015',
            'result' => [
                'merchantType' => '30',
                'bakongAccountID' => '',
                'accountInformation' => null,
                'merchantID' => null,
                'acquiringBank' => null,
                'billNumber' => null,
                'mobileNumber' => null,
                'storeLabel' => null,
                'terminalLabel' => null,
                'purposeOfTransaction' => null,
                'languagePreference' => null,
                'merchantNameAlternateLanguage' => null,
                'merchantCityAlternateLanguage' => null,
                'creationTimestamp' => null,
                'expirationTimestamp' => null,
                'payloadFormatIndicator' => '01',
                'pointofInitiationMethod' => '12',
                'unionPayMerchant' => null,
                'merchantCategoryCode' => null,
                'transactionCurrency' => null,
                'transactionAmount' => null,
                'countryCode' => null,
                'merchantName' => null,
                'merchantCity' => null,
                'crc' => null,
            ],
        ],
        [
            'statement' => 'Decode Test 11',
            'data' => '10263041234',
            'result' => [
                'merchantType' => null,
                'bakongAccountID' => null,
                'accountInformation' => null,
                'merchantID' => null,
                'acquiringBank' => null,
                'billNumber' => null,
                'mobileNumber' => null,
                'storeLabel' => null,
                'terminalLabel' => null,
                'purposeOfTransaction' => null,
                'languagePreference' => null,
                'merchantNameAlternateLanguage' => null,
                'merchantCityAlternateLanguage' => null,
                'creationTimestamp' => null,
                'expirationTimestamp' => null,
                'payloadFormatIndicator' => null,
                'pointofInitiationMethod' => null,
                'unionPayMerchant' => null,
                'merchantCategoryCode' => null,
                'transactionCurrency' => null,
                'transactionAmount' => null,
                'countryCode' => null,
                'merchantName' => null,
                'merchantCity' => null,
                'crc' => null,
            ],
        ],
        [
            'statement' => 'Decode Test 12',
            'data' => '63041234',
            'result' => [
                'merchantType' => null,
                'bakongAccountID' => null,
                'accountInformation' => null,
                'merchantID' => null,
                'acquiringBank' => null,
                'billNumber' => null,
                'mobileNumber' => null,
                'storeLabel' => null,
                'terminalLabel' => null,
                'purposeOfTransaction' => null,
                'languagePreference' => null,
                'merchantNameAlternateLanguage' => null,
                'merchantCityAlternateLanguage' => null,
                'creationTimestamp' => null,
                'expirationTimestamp' => null,
                'payloadFormatIndicator' => null,
                'pointofInitiationMethod' => null,
                'unionPayMerchant' => null,
                'merchantCategoryCode' => null,
                'transactionCurrency' => null,
                'transactionAmount' => null,
                'countryCode' => null,
                'merchantName' => null,
                'merchantCity' => null,
                'crc' => '1234',
            ],
        ],
        [
            'statement' => 'Decode Test 13',
            'data' => '00020101021230410015john_smith@devb01061234560208Dev Bank53038405204599954035.05802KH5916john smith actor6010Phnom Penh62150111Invoice#06999170013161343857589263040437',
            'result' => [
                'merchantType' => '30',
                'bakongAccountID' => 'john_smith@devb',
                'accountInformation' => null,
                'merchantID' => '123456',
                'acquiringBank' => 'Dev Bank',
                'billNumber' => 'Invoice#069',
                'mobileNumber' => null,
                'storeLabel' => null,
                'terminalLabel' => null,
                'purposeOfTransaction' => null,
                'languagePreference' => null,
                'merchantNameAlternateLanguage' => null,
                'merchantCityAlternateLanguage' => null,
                'creationTimestamp' => '1613438575892',
                'expirationTimestamp' => null,
                'payloadFormatIndicator' => '01',
                'pointofInitiationMethod' => '12',
                'unionPayMerchant' => null,
                'merchantCategoryCode' => '5999',
                'transactionCurrency' => '840',
                'transactionAmount' => '5.0',
                'countryCode' => 'KH',
                'merchantName' => 'john smith actor',
                'merchantCity' => 'Phnom Penh',
                'crc' => '0437',
            ],
        ],
        [
            'statement' => 'Decode Test 14',
            'data' => '00020101021252045999530384054035.05802KH5916john smith actor6010Phnom Penh62150111Invoice#06999170013161343857589263042494',
            'result' => [
                'merchantType' => null,
                'bakongAccountID' => null,
                'accountInformation' => null,
                'merchantID' => null,
                'acquiringBank' => null,
                'billNumber' => 'Invoice#069',
                'mobileNumber' => null,
                'storeLabel' => null,
                'terminalLabel' => null,
                'purposeOfTransaction' => null,
                'languagePreference' => null,
                'merchantNameAlternateLanguage' => null,
                'merchantCityAlternateLanguage' => null,
                'creationTimestamp' => '1613438575892',
                'expirationTimestamp' => null,
                'payloadFormatIndicator' => '01',
                'pointofInitiationMethod' => '12',
                'unionPayMerchant' => null,
                'merchantCategoryCode' => '5999',
                'transactionCurrency' => '840',
                'transactionAmount' => '5.0',
                'countryCode' => 'KH',
                'merchantName' => 'john smith actor',
                'merchantCity' => 'Phnom Penh',
                'crc' => '2494',
            ],
        ],
        [
            'statement' => 'Decode Test 15',
            'data' => '000201010212301900151234567890123456304D807',
            'result' => [
                'merchantType' => '30',
                'bakongAccountID' => '123456789012345',
                'accountInformation' => null,
                'merchantID' => null,
                'acquiringBank' => null,
                'billNumber' => null,
                'mobileNumber' => null,
                'storeLabel' => null,
                'terminalLabel' => null,
                'purposeOfTransaction' => null,
                'languagePreference' => null,
                'merchantNameAlternateLanguage' => null,
                'merchantCityAlternateLanguage' => null,
                'creationTimestamp' => null,
                'expirationTimestamp' => null,
                'payloadFormatIndicator' => '01',
                'pointofInitiationMethod' => '12',
                'unionPayMerchant' => null,
                'merchantCategoryCode' => null,
                'transactionCurrency' => null,
                'transactionAmount' => null,
                'countryCode' => null,
                'merchantName' => null,
                'merchantCity' => null,
                'crc' => 'D807',
            ],
        ],
        [
            'statement' => 'Decode Test 16',
            'data' => '00020101021230440040123456789012345678901234567890123456789063041747',
            'result' => [
                'merchantType' => '30',
                'bakongAccountID' => '1234567890123456789012345678901234567890',
                'accountInformation' => null,
                'merchantID' => null,
                'acquiringBank' => null,
                'billNumber' => null,
                'mobileNumber' => null,
                'storeLabel' => null,
                'terminalLabel' => null,
                'purposeOfTransaction' => null,
                'languagePreference' => null,
                'merchantNameAlternateLanguage' => null,
                'merchantCityAlternateLanguage' => null,
                'creationTimestamp' => null,
                'expirationTimestamp' => null,
                'payloadFormatIndicator' => '01',
                'pointofInitiationMethod' => '12',
                'unionPayMerchant' => null,
                'merchantCategoryCode' => null,
                'transactionCurrency' => null,
                'transactionAmount' => null,
                'countryCode' => null,
                'merchantName' => null,
                'merchantCity' => null,
                'crc' => '1747',
            ],
        ],
        [
            'statement' => 'Decode Test 17',
            'data' => '000301001021230190015john_smith@devb630493FD',
            'result' => [
                'merchantType' => '30',
                'bakongAccountID' => 'john_smith@devb',
                'accountInformation' => null,
                'merchantID' => null,
                'acquiringBank' => null,
                'billNumber' => null,
                'mobileNumber' => null,
                'storeLabel' => null,
                'terminalLabel' => null,
                'purposeOfTransaction' => null,
                'languagePreference' => null,
                'merchantNameAlternateLanguage' => null,
                'merchantCityAlternateLanguage' => null,
                'creationTimestamp' => null,
                'expirationTimestamp' => null,
                'payloadFormatIndicator' => '010',
                'pointofInitiationMethod' => '12',
                'unionPayMerchant' => null,
                'merchantCategoryCode' => null,
                'transactionCurrency' => null,
                'transactionAmount' => null,
                'countryCode' => null,
                'merchantName' => null,
                'merchantCity' => null,
                'crc' => '93FD',
            ],
        ],
    ];

    public function test_decode()
    {
        foreach ($this->testData as $data) {
            $decoded = BakongKHQR::decode($data['data']);
            $this->assertEquals($data['result'], (array) $decoded->data, $data['statement']);
        }
    }
}
