<?php
namespace App\Libs\TikTok\MiniProgram\Pay;

use ArrayAccess;
use App\Libs\TikTok\Kernel\Traits\HasAttributes;

/**
 * Class Message
 * @package App\Libs\TikTok\MiniProgram\Pay
 * @property array $msg
 */
class Message implements ArrayAccess
{
    use HasAttributes;

    public const TYPE_PAY = 'payment';

    public const TYPE_REFUND = 'refund';

    public const TYPE_SETTLED = 'settle';

    public function getType(): string
    {
        $type = $this->toArray()['type'] ?? '';
        if (empty($type)) {
            throw new \RuntimeException('Invalid event type.');
        }
        return $type;
    }
}
