<?php

namespace App\Controllers;

use App\Core\Request;
use App\Core\Response;

/**
 * Foundation controller offering model loading, request parsing, and validation helpers.
 */
class BaseController
{
    /**
     * Validate request payload and return array of errors if any fail
     *
     * @param Request $request
     * @param array $rules List of keys and their validation constraints (e.g. ['email' => 'required|email'])
     * @return array Empty if valid, otherwise contains error messages
     */
    protected function validate(Request $request, array $rules): array
    {
        $validator = new \App\Core\Validator();
        $validator->validate($request->getBody(), $rules);
        return $validator->getErrors();
    }
}
