<?php

declare(strict_types=1);

define('BASEPATH', __DIR__);

class CI_Model
{
}

require dirname(__DIR__) . '/application/models/M_core.php';

$model = new M_Core();
$method = new ReflectionMethod(M_Core::class, 'detectBrowserPushEvent');
$method->setAccessible(true);

$cases = array(
    array('0.005 USD from AdscendMedia Offer: Survey was credited to your balance.', 1, 'offer_credited'),
    array('Your pending withdrawal #125 was processed.', 1, 'withdrawal_paid'),
    array('Your pending withdrawal #125 has been rejected.', 2, ''),
    array('0.005 USD from Lottery was credited to your balance.', 1, ''),
    array('0.005 USD from Offerwall Offer: Survey was credited to your balance.', 2, '')
);

foreach ($cases as $index => $case) {
    $actual = $method->invoke($model, $case[0], $case[1]);
    if ($actual !== $case[2]) {
        throw new RuntimeException(sprintf(
            'Case %d failed: expected "%s", received "%s".',
            $index + 1,
            $case[2],
            $actual
        ));
    }
}

fwrite(STDOUT, "PASS: Offer and withdrawal notification events are classified correctly.\n");
