package de.avatic.lcc.controller.custom;

import de.avatic.lcc.service.CustomApiService;
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;

/**
 * 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;

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

    /**
     * Retrieves the tariff rate for the specified HS code and country ID.
     *
     * @param hsCode    the HS code representing the product classification
     * @param countryId 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<Number> getTariffRate(@RequestParam(value = "hs_code") String hsCode, @RequestParam(value = "country_id") Integer countryId) {
        return ResponseEntity.ok(customApiService.getTariffRate(hsCode, countryId));
    }

}
