<?php

namespace AIPT\Api\Chatbot\Exceptions;

class ProviderAuthException extends ChatbotException {

	protected $error_code = 'provider_auth_error';
	protected $recoverable = false;
	protected $http_status = 503;

	private string $provider;
	private int $provider_status;

	public function __construct( string $message = '', string $provider = '', int $provider_status = 0, int $code = 0, ?\Throwable $previous = null ) {
		$this->provider        = $provider;
		$this->provider_status = $provider_status;

		if ( 401 === $provider_status || 403 === $provider_status ) {
			$this->http_status = $provider_status;
		}

		parent::__construct( $message ?: __( 'Provider authentication failed.', 'ai-product-tools' ), $code, $previous );
	}

	public function getProvider(): string {
		return $this->provider;
	}

	public function getProviderStatus(): int {
		return $this->provider_status;
	}

	public function getUserMessage(): string {
		return __( 'Configuration issue, please contact admin', 'ai-product-tools' );
	}
}
