package de.oaa.xxx.hashtag;

import org.springframework.http.ResponseEntity;
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 java.util.List;

@RestController
@RequestMapping("/hashtags")
public class HashtagController {

    private final HashtagService hashtagService;

    public HashtagController(HashtagService hashtagService) {
        this.hashtagService = hashtagService;
    }

    /** Autocomplete: ?q=ki → ["kinky","kink",...]. Empty q returns popular. */
    @GetMapping("/suggest")
    public ResponseEntity<List<String>> suggest(
            @RequestParam(defaultValue = "") String q,
            @RequestParam(defaultValue = "6") int limit) {
        return ResponseEntity.ok(hashtagService.suggest(q.stripLeading().replaceFirst("^#", ""), limit));
    }

    /** Popular hashtags of the last 30 days. */
    @GetMapping("/popular")
    public ResponseEntity<List<String>> popular(
            @RequestParam(defaultValue = "10") int limit) {
        return ResponseEntity.ok(hashtagService.getPopular(limit));
    }
}
