<?php

namespace App\Domains\Auth\Controllers;

use App\Domains\Auth\Requests\RegisterUserRequest;
use App\Domains\Auth\Resources\UserResource;
use App\Domains\Auth\Services\RegisterUserService;
use App\Http\Controllers\Controller;
use Illuminate\Http\JsonResponse;

class RegisterController extends Controller
{
    public function __construct(
        protected RegisterUserService $registerUserService,
    ) {}

    public function __invoke(RegisterUserRequest $request): JsonResponse
    {
        $user = $this->registerUserService->register($request->validated());

        return UserResource::make($user)
            ->additional([
                'code' => 'auth.register_success',
                'message' => __('api.auth.register_success'),
            ])
            ->response()
            ->setStatusCode(201);
    }
}
