package com.tasteby.controller;

import com.tasteby.domain.UserInfo;
import com.tasteby.security.AuthUtil;
import com.tasteby.service.AuthService;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

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

    private final AuthService authService;

    public AuthController(AuthService authService) {
        this.authService = authService;
    }

    @PostMapping("/google")
    public Map<String, Object> loginGoogle(@RequestBody Map<String, String> body) {
        String idToken = body.get("id_token");
        return authService.loginGoogle(idToken);
    }

    @GetMapping("/me")
    public UserInfo me() {
        String userId = AuthUtil.getUserId();
        return authService.getCurrentUser(userId);
    }
}
