package demo;

import jakarta.validation.Valid;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

record NewItem(@NotBlank String name, @Min(1) int qty) {}

@RestController
class ValidController {
    @PostMapping("/api/new")
    Map<String, Object> create(@Valid @RequestBody NewItem item) {
        return Map.of("created", item.name(), "qty", item.qty());
    }
}

@Controller
class ViewController {
    @GetMapping("/view")
    String view() { return "items"; }          // a view NAME, not a body
}

interface Greeter { String hi(); }

@Component @Profile("ambiguous")
class EnGreeter implements Greeter { public String hi() { return "hello"; } }

@Component @Profile("ambiguous")
class FrGreeter implements Greeter { public String hi() { return "bonjour"; } }

@Component @Profile("ambiguous")
class NeedsGreeter {
    NeedsGreeter(Greeter greeter) { }
}
