<?php
/**
 * Validation Exception
 *
 * Exception for validation errors
 *
 * @package NemtlyBooking
 * @since   PBOOKING_SINCE
 */

namespace NemtlyBooking\Exceptions;

/**
 * Validation Exception class
 *
 * @since PBOOKING_SINCE
 */
class Validation_Exception extends Nemtly_Booking_Exception {

    /**
     * Validation errors
     *
     * @var array
     */
    private $validation_errors;

    /**
     * Constructor
     *
     * @since PBOOKING_SINCE
     *
     * @param string $message            Exception message.
     * @param array  $validation_errors  Validation errors.
     * @param string $error_code        Error code.
     * @param array  $error_data         Error data.
     */
    public function __construct( $message = '', $validation_errors = [], $error_code = 'validation_failed', $error_data = [] ) {
        parent::__construct( $message, $error_code, $error_data, 400 );
        $this->validation_errors = $validation_errors;
    }

    /**
     * Get validation errors
     *
     * @since PBOOKING_SINCE
     *
     * @return array Validation errors.
     */
    public function get_validation_errors() {
        return $this->validation_errors;
    }

    /**
     * Add validation error
     *
     * @since PBOOKING_SINCE
     *
     * @param string $field   Field name.
     * @param string $message Error message.
     */
    public function add_validation_error( $field, $message ) {
        $this->validation_errors[ $field ] = $message;
    }

    /**
     * Check if has validation errors
     *
     * @since PBOOKING_SINCE
     *
     * @return bool True if has errors, false otherwise.
     */
    public function has_validation_errors() {
        return ! empty( $this->validation_errors );
    }
}
