package org.raddatz.familienarchiv.user;

import io.swagger.v3.oas.annotations.Operation;
import lombok.RequiredArgsConstructor;
import org.raddatz.familienarchiv.user.PasswordResetTestHelper;
import org.springframework.context.annotation.Profile;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * Test-only endpoint to retrieve a password reset token by email.
 * Only active under the "e2e" Spring profile.
 */
@RestController
@RequestMapping("/api/auth")
@Profile("e2e")
@RequiredArgsConstructor
public class AuthE2EController {

    private final PasswordResetTestHelper passwordResetTestHelper;

    // Hidden from the OpenAPI spec — this endpoint must never appear in the generated api.ts
    // even when the e2e profile is active alongside the dev profile during spec generation.
    @Operation(hidden = true)
    @GetMapping("/reset-token-for-test")
    public ResponseEntity<String> getResetTokenForTest(@RequestParam String email) {
        return passwordResetTestHelper.getResetTokenForTest(email)
                .map(ResponseEntity::ok)
                .orElse(ResponseEntity.notFound().build());
    }
}
