package com.tasteby.controller;

import com.tasteby.domain.Restaurant;
import com.tasteby.service.SearchService;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api/search")
public class SearchController {

    private final SearchService searchService;

    public SearchController(SearchService searchService) {
        this.searchService = searchService;
    }

    @GetMapping
    public List<Restaurant> search(
            @RequestParam String q,
            @RequestParam(defaultValue = "keyword") String mode,
            @RequestParam(defaultValue = "20") int limit) {
        if (limit > 100) limit = 100;
        return searchService.search(q, mode, limit);
    }
}
