package com.writeoff.module.system.controller;

import com.writeoff.common.api.ApiResponse;
import com.writeoff.module.system.model.GlobalSearchResult;
import com.writeoff.module.system.service.GlobalSearchService;
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;

@RestController
@RequestMapping("/api/search")
public class GlobalSearchController {
    private final GlobalSearchService globalSearchService;

    public GlobalSearchController(GlobalSearchService globalSearchService) {
        this.globalSearchService = globalSearchService;
    }

    @GetMapping("/global")
    public ApiResponse<GlobalSearchResult> global(@RequestParam(value = "q", required = false) String keyword,
                                                  @RequestParam(value = "limitPerType", required = false) Integer limitPerType) {
        return ApiResponse.success(globalSearchService.search(keyword, limitPerType));
    }
}
