import { ApiValidationError } from "../../Models/Server.Error.model";
import { Body, Controller, Post, Response, Route, SuccessResponse } from "tsoa";
import { SignUpService } from "./SignUp.Service";
import { IUser, SignUpParams } from "../../Models/Users/Users.Interface";

@Route("users/signup")
export class SignUpController extends Controller {
    @Response<ApiValidationError>(500, "Ha ocurrido un error")
    @SuccessResponse("200", "Registered User") // Custom success response
    @Post()
    public async signUp(@Body() requestBody: SignUpParams): Promise<IUser | ApiValidationError> {
        try {
            const user: IUser = await new SignUpService().signUp(requestBody);
            this.setStatus(200);
            return user;
        } catch (e) {
            const errorOccured: Error = e as Error;
            this.setStatus(500);
            return new ApiValidationError(500, errorOccured.message);
        }
    }
}
