package com.reading.platform.controller;

import com.reading.platform.common.response.Result;
import com.reading.platform.dto.request.LoginRequest;
import com.reading.platform.dto.response.LoginResponse;
import com.reading.platform.dto.response.UserInfoResponse;
import com.reading.platform.service.AuthService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@Tag(name = "Auth", description = "Authentication APIs")
@RestController
@RequestMapping("/api/auth")
@RequiredArgsConstructor
public class AuthController {

    private final AuthService authService;

    @Operation(summary = "User login")
    @PostMapping("/login")
    public Result<LoginResponse> login(@Valid @RequestBody LoginRequest request) {
        return Result.success(authService.login(request));
    }

    @Operation(summary = "Get current user info")
    @GetMapping("/me")
    public Result<UserInfoResponse> getCurrentUser() {
        return Result.success(authService.getCurrentUserInfo());
    }

    @Operation(summary = "Change password")
    @PostMapping("/change-password")
    public Result<Void> changePassword(
            @RequestParam String oldPassword,
            @RequestParam String newPassword) {
        authService.changePassword(oldPassword, newPassword);
        return Result.success();
    }

}
