package de.avatic.lcc.controller.custom;

import de.avatic.lcc.dto.custom.CustomDTO;
import de.avatic.lcc.model.taric.Nomenclature;
import de.avatic.lcc.service.api.CustomApiService;
import de.avatic.lcc.service.api.EUTaxationApiWrapperService;
import de.avatic.lcc.service.calculation.NomenclatureService;
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;

/**
 * Controller for handling custom tariff related requests.
 * Provides endpoints for retrieving tariff rates based on HS code and country ID.
 */
@RestController
@RequestMapping("/api/customs")
public class CustomController {


    private final CustomApiService customApiService;
    private final NomenclatureService nomenclatureService;
    private final EUTaxationApiWrapperService eUTaxationApiWrapperService;

    /**
     * Constructs a new instance of CustomController with the given service.
     *
     * @param customApiService the service responsible for custom tariff calculations
     */
    public CustomController(CustomApiService customApiService, NomenclatureService nomenclatureService, EUTaxationApiWrapperService eUTaxationApiWrapperService) {
        this.customApiService = customApiService;
        this.nomenclatureService = nomenclatureService;
        this.eUTaxationApiWrapperService = eUTaxationApiWrapperService;
    }

    /**
     * Retrieves the tariff rate for the specified HS code and country ID.
     *
     * @param hsCode    the HS code representing the product classification
     * @param countryIds the ID of the country for which the tariff rate is required
     * @return a {@code ResponseEntity} containing the tariff rate as a {@code Number}
     */
    @GetMapping({"/",""})
    public ResponseEntity<List<CustomDTO>> getTariffRate(@RequestParam(value = "hs_code") String hsCode, @RequestParam(value = "country_ids") List<Integer> countryIds) {
        var res = eUTaxationApiWrapperService.getTariffRates(hsCode, countryIds);
        return ResponseEntity.ok(res);
    }

    @GetMapping({"/search", "/search/"})
    public ResponseEntity<List<String>> getNomenclature(@RequestParam(value = "hs_code") String hsCode) {
        return ResponseEntity.ok(nomenclatureService.getNomenclature(hsCode));
    }

}
