package com.realnet.auth.controller;

import com.realnet.auth.dto.AuthResponse;
import com.realnet.auth.dto.RegisterRequest;
import com.realnet.auth.dto.LoginRequest;
import com.realnet.auth.dto.PasswordResetRequest;
import com.realnet.auth.service.UserService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/api/v1/auth")
@RequiredArgsConstructor
public class AuthController {

    private final UserService userService;

    @PostMapping("/register")
    public ResponseEntity<AuthResponse> register(
            @RequestBody RegisterRequest request
    ) {
        return ResponseEntity.ok(userService.register(request));
    }

    @PostMapping("/login")
    public ResponseEntity<AuthResponse> login(
            @RequestBody LoginRequest request
    ) {
        return ResponseEntity.ok(userService.login(request));
    }

    @PostMapping("/password-reset")
    public ResponseEntity<String> initiatePasswordReset(
            @RequestBody PasswordResetRequest request
    ) {
        userService.initiatePasswordReset(request);
        return ResponseEntity.ok("Password reset initiated. Check your email.");
    }
}
