package de.avatic.taric.controller;

import de.avatic.taric.model.Nomenclature;
import de.avatic.taric.service.NomenclatureService;
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;
import java.util.Optional;

@RestController
@RequestMapping("/api/v1/nomenclature")
public class NomenclatureController {

    private final NomenclatureService nomenclatureService;

    public NomenclatureController(NomenclatureService nomenclatureService) {
        this.nomenclatureService = nomenclatureService;
    }

    @GetMapping("")
    public Optional<Nomenclature> getNomenclature(@RequestParam String hscode) {
        return nomenclatureService.getNomenclature(hscode);
    }

    @GetMapping("/declarable")
    public List<Nomenclature> getDeclarable(@RequestParam String hscode) {
        return nomenclatureService.getDeclarableChildren(hscode);
    }

    @GetMapping("/cascade")
    public List<Nomenclature> getCascade(@RequestParam String hscode) {
        var found = nomenclatureService.getNomenclatureCascade(hscode);
        return found;
    }

}
