<?php

use Illuminate\Auth\AuthenticationException;
use Illuminate\Foundation\Application;
use Illuminate\Foundation\Configuration\Exceptions;
use Illuminate\Foundation\Configuration\Middleware;
use Illuminate\Validation\ValidationException;

return Application::configure(basePath: dirname(__DIR__))
    ->withRouting(
        web: __DIR__ . '/../routes/web.php',
        api: __DIR__ . '/../routes/api.php',
        commands: __DIR__ . '/../routes/console.php',
        health: '/up',
    )
    ->withMiddleware(function (Middleware $middleware) {
        //
    })
    ->withExceptions(function (Exceptions $exceptions) {
        if (request()->is('api/*')) {
            $exceptions->renderable(function (AuthenticationException $exception) {
                return response()->json([
                    'error' => true,
                    'message' => $exception->getMessage(),
                    'response' => NULL
                ], 200);
            });
            $exceptions->renderable(function (\Illuminate\Validation\ValidationException $exception) {
                return response()->json([
                    'error' => true,
                    'message' => $exception->getMessage(),
                    'response' => NULL
                ], 200);
            });
        }
    })->create();
