import { RecoveryAccountParams } from "../../Models/Users/Users.Interface";
import { ApiValidationError } from "../../Models/Server.Error.model";
import { Body, Controller, Post, Response, Route, SuccessResponse, Middlewares } from "tsoa";
import { RecoveryAccountService } from "./RecoveryAccount.Service";
import { ApiVoidResult } from "../../Models/Api.VoidResult.type";
import { rateLimiter } from "../../middleware/ratelimiter";

@Route("users/recovery")
@Middlewares(rateLimiter)
export class RecoverAccountController extends Controller {
    @Response<ApiValidationError>(500, "Ha ocurrido un error")
    @SuccessResponse("200", "Success") // Custom success response
    @Post()
    public async recoveryAccount(
        @Body() requestBody: RecoveryAccountParams
    ): Promise<ApiVoidResult | ApiValidationError> {
        try {
            await new RecoveryAccountService().recoveryAccount(requestBody);
            this.setStatus(200);
            return {
                success: true,
                message: "Done",
            };
        } catch (e) {
            const errorOccured: Error = e as Error;
            this.setStatus(500);
            return new ApiValidationError(500, errorOccured.message);
        }
    }
}
