package com.example.demo.controller;

import java.util.Map;

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;

import com.example.demo.repository.UserRepository;

@RestController
@RequestMapping("/api/public")
public class PublicApiController {

    private final UserRepository userRepository;

    public PublicApiController(UserRepository userRepository) {
        this.userRepository = userRepository;
    }

    @GetMapping("/users/exists/username")
    public Map<String, Boolean> existsUsername(@RequestParam("value") String username) {
        return Map.of("exists", userRepository.existsByUsername(username));
    }

    @GetMapping("/users/exists/email")
    public Map<String, Boolean> existsEmail(@RequestParam("value") String email) {
        return Map.of("exists", userRepository.existsByEmail(email));
    }
}



