<?php

declare(strict_types=1);

namespace apexl\Io\modules\user\Request;

use apexl\Io\includes\RouteManager;
use apexl\Io\modules\userDisplay\FormBuilders\RegisterFormBuilder;
use apexl\Io\modules\validation\Interfaces\HasValidationRulesInterface;
use apexl\Io\modules\validation\Interfaces\ValidatesDataInterface;
use apexl\Io\modules\validation\Traits\ValidatesData;
use apexl\Io\Request\IoRequest;
use Psr\Http\Message\StreamInterface;
use Psr\Http\Message\UriInterface;
use Slim\Psr7\Interfaces\HeadersInterface;

final class RegisterRequest extends IoRequest implements ValidatesDataInterface
{
    use ValidatesData;

    public function __construct(
        $method,
        UriInterface $uri,
        HeadersInterface $headers,
        array $cookies,
        array $serverParams,
        StreamInterface $body,
        array $uploadedFiles,
        private readonly RegisterFormBuilder $formBuilder,
        private readonly RouteManager $routeManager,
    ) {
        parent::__construct(
            $method,
            $uri,
            $headers,
            $cookies,
            $serverParams,
            $body,
            $uploadedFiles,
        );
    }

    public function firstName(): string
    {
        return $this->bodyParam('first_name');
    }

    public function lastName(): string
    {
        return $this->bodyParam('last_name');
    }

    public function email(): string
    {
        return $this->bodyParam('email');
    }

    public function password(): string
    {
        return $this->bodyParam('password');
    }

    public function redirect(): string
    {
        return $this->bodyParam('redirect') ?: $this->routeManager->getRoutePattern('user.display.login');
    }

    public function validationRules(): HasValidationRulesInterface
    {
        return $this->formBuilder;
    }
}
