<?php

namespace AuthStack\SAMLServiceProvider\Exceptions;

use Throwable;

class SAMLException extends \Exception
{
    protected $status_code;

    public function __construct(string $message = "", int $code = 0, Throwable $previous = null)
    {
        parent::__construct($message, $code, $previous);

        $this->status_code = $code;
    }

    /**
     * @return \Illuminate\Http\JsonResponse
     */
    public function render()
    {
        return response()->json(['error' => $this->getMessage()], $this->getStatusCode());
    }

    public function report()
    {}

    /**
     * @return int
     */
    protected function getStatusCode(): int
    {
        if(empty($this->status_code))
        {
            return 500;
        }

        return $this->status_code;
    }
}