<?php

namespace AIPT\Api\Chatbot\Exceptions;

/**
 * Exception for invalid request errors (HTTP 400).
 *
 * Thrown when the request to AI provider is malformed or invalid.
 * This error is NOT recoverable without fixing the request.
 *
 * @package AIPT\Api\Chatbot\Exceptions
 * @since 2.5.0
 */
class InvalidRequestException extends ChatbotException {

    /**
     * Error code for client response.
     *
     * @var string
     */
    protected $error_code = 'invalid_request';

    /**
     * This error is not recoverable without fixing the request.
     *
     * @var bool
     */
    protected $recoverable = false;

    /**
     * HTTP status code.
     *
     * @var int
     */
    protected $http_status = 400;

    /**
     * Constructor.
     *
     * @param string          $message  Error message.
     * @param int             $code     Exception code.
     * @param \Throwable|null $previous Previous exception.
     */
    public function __construct(
        string $message = '',
        int $code = 0,
        ?\Throwable $previous = null
    ) {
        parent::__construct($message ?: __('Invalid request to AI service.', 'ai-product-tools'), $code, $previous);
    }

    /**
     * Get user-friendly error message.
     *
     * @return string
     */
    public function getUserMessage(): string {
        return __('There was a problem processing your request. Please try rephrasing your question.', 'ai-product-tools');
    }
}
