<?php

if (! defined('ABSPATH')) {
    exit;
} class PufferGo_API_Exception extends Exception
{
    public const CONSOLE_BASE_URL = 'https://puffergo.com/dashboard';

    public const ERROR_AUTH_INVALID = 'auth_invalid';

    public const ERROR_CREDITS_INSUFFICIENT = 'credits_insufficient';

    protected $action_url = null;

    protected $error_type = null;

    public function __construct($message = '', $code = 0, $error_type = null, $action_url = null, $previous = null)
    {
        parent::__construct($message, $code, $previous);
        $this->error_type = $error_type;
        $this->action_url = $action_url;
    }

    public function getActionUrl()
    {
        return $this->action_url;
    }

    public function getErrorType()
    {
        return $this->error_type;
    }

    public static function authInvalid($code = 401)
    {
        return new self(__('Invalid or disabled API key. Please go to the console to re-authorize.', 'puffergo'), $code, self::ERROR_AUTH_INVALID, self::CONSOLE_BASE_URL);
    }

    public static function creditsInsufficient()
    {
        return new self(__('Insufficient AI credits. Please go to the console to upgrade your plan or top up.', 'puffergo'), 402, self::ERROR_CREDITS_INSUFFICIENT, self::CONSOLE_BASE_URL . '/billing');
    }

    public function toArray()
    {
        return array('success' => false, 'error_code' => $this->getCode(), 'error_type' => $this->error_type, 'message' => $this->getMessage(), 'action_url' => $this->action_url, );
    }
}
