<?php

namespace App\Services\Fcm;

use Exception;

class FcmException extends Exception
{
    public function __construct(
        string $message,
        public readonly int $httpStatusCode = 0,
        public readonly array $response = [],
        ?\Throwable $previous = null
    ) {
        parent::__construct($message, 0, $previous);
    }

    /**
     * HTTP 응답에서 예외 생성
     */
    public static function fromResponse(int $statusCode, array $response): self
    {
        $message = $response['error']['message'] ?? 'Unknown FCM error';

        return new self($message, $statusCode, $response);
    }
}
