<?php

declare(strict_types=1);

namespace App\Controllers;

use App\Helpers\Request;
use App\Helpers\Response;
use App\Helpers\Validator;

abstract class BaseController
{
    protected Request $request;

    public function __construct(Request $request)
    {
        $this->request = $request;
    }

    protected function validate(array $data, callable $rules): Validator
    {
        $validator = new Validator($data);
        $rules($validator);
        return $validator;
    }

    protected function getAuthUserId(): int
    {
        return (int) $this->request->param('auth_user_id', 0);
    }

    protected function getAuthUserRole(): string
    {
        return $this->request->param('auth_user_role', '');
    }

    protected function getAuthUserEventId(): ?int
    {
        $id = $this->request->param('auth_user_event_id');
        return $id !== null ? (int) $id : null;
    }

    protected function getRouteParam(string $key, mixed $default = null): mixed
    {
        return $this->request->param($key, $default);
    }
}
