public function registerDevice(string $deviceId, string $platform, ?string $userData = null): string
    {
        if (!isset($this->arns[$platform])) {
            throw new PlatformNotConfiguredException("There is no configured ARN for $platform");
        }

        try {
            $args = [
                'PlatformApplicationArn' => $this->arns[$platform],
                'Token' => $deviceId,
                'Attributes' => [
                    'Enabled' => 'true',
                ],
            ];

            if ($userData) {
                $args['CustomUserData'] = $userData;
            }

            $res = $this->sns->createPlatformEndpoint($args);
        } catch (SnsException $e) {
            preg_match('/Endpoint (.+?) already/', $e->getMessage(), $matches);
            if (isset($matches[1])) {
                $this->sns->setEndpointAttributes(
                    [
                        'EndpointArn' => $matches[1],
                        'Attributes' => [
                            'Enabled' => 'true',
                        ],
                    ]
                );

                return $matches[1];
            } else {
                throw $e;
            }
        }

        return $res['EndpointArn'];
    }