<?php

namespace App\Core\Exceptions;

use Exception;
use Illuminate\Http\JsonResponse;

class ValidationException extends ServiceException
{
    protected array $errors;

    public function __construct(string $message = 'Validation failed', array $errors = [])
    {
        parent::__construct($message, 'VALIDATION_ERROR', 422);
        $this->errors = $errors;
    }

    public function render(): JsonResponse
    {
        return response()->json([
            'success' => false,
            'message' => $this->getMessage(),
            'error_code' => $this->getErrorCode(),
            'errors' => $this->errors,
        ], $this->statusCode);
    }

    public function getErrors(): array
    {
        return $this->errors;
    }
}
