package de.avatic.taric.controller;

import de.avatic.taric.service.TariffService2;
//import de.avatic.taric.service.TariffService2.TariffResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.Pattern;
import java.math.BigDecimal;
import java.util.HashMap;
import java.util.Map;

//@RestController
//@RequestMapping("/api/v1/tariff")

@Tag(name = "Tariff API", description = "API zur Abfrage von Zolltarifen")
public class TariffController2 {

//    private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(TariffController2.class);
//
//    private final TariffService2 tariffService;
//
//    public TariffController2(TariffService2 tariffService) {
//        this.tariffService = tariffService;
//    }
//
//    @GetMapping("/rate")
//    @Operation(summary = "Zolltarif abfragen",
//            description = "Ermittelt den Zolltarif für einen HS-Code und ein Herkunftsland")
//    @ApiResponses(value = {
//            @ApiResponse(responseCode = "200", description = "Tarif erfolgreich gefunden"),
//            @ApiResponse(responseCode = "404", description = "Kein Tarif gefunden"),
//            @ApiResponse(responseCode = "400", description = "Ungültige Eingabeparameter")
//    })
//    public ResponseEntity<TariffResponse> getTariffRate(
//            @Parameter(description = "HS-Code (6, 8 oder 10 Stellen)", example = "850410")
//            @RequestParam
//            @NotBlank(message = "HS Code ist erforderlich")
//            @Pattern(regexp = "^[0-9]{4,10}$", message = "HS Code muss 4-10 Ziffern enthalten")
//            String hsCode,
//
//            @Parameter(description = "ISO-2 Ländercode", example = "CN")
//            @RequestParam
//            @NotBlank(message = "Ländercode ist erforderlich")
//            @Pattern(regexp = "^[A-Z]{2}$", message = "Ländercode muss 2 Großbuchstaben sein")
//            String countryCode) {
//
//        log.info("Tariff rate request - HS Code: {}, Country: {}", hsCode, countryCode);
//
//        try {
//            TariffResult result = tariffService.getTariffRate(hsCode, countryCode);
//
//            if (result.isFound()) {
//                TariffResponse response = TariffResponse.success(
//                        result.getRate(),
//                        result.getHsCode(),
//                        result.getCountryCode()
//                );
//                return ResponseEntity.ok(response);
//            } else {
//                TariffResponse response = TariffResponse.notFound(result.getMessage());
//                return ResponseEntity.status(HttpStatus.NOT_FOUND).body(response);
//            }
//
//        } catch (Exception e) {
//            log.error("Error getting tariff rate", e);
//            TariffResponse response = TariffResponse.error("Internal server error: " + e.getMessage());
//            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(response);
//        }
//    }
//
//    @GetMapping("/health")
//    @Operation(summary = "Health Check", description = "Prüft ob der Service verfügbar ist")
//    public ResponseEntity<Map<String, String>> health() {
//        Map<String, String> response = new HashMap<>();
//        response.put("status", "UP");
//        response.put("service", "TARIC Tariff Service");
//        return ResponseEntity.ok(response);
//    }
//
//    /**
//     * Response-Klasse für Tarif-Abfragen
//     */
//    public static class TariffResponse {
//        private final boolean success;
//        private final BigDecimal tariffRate;
//        private final String hsCode;
//        private final String countryCode;
//        private final String message;
//        private final String formattedRate;
//
//        private TariffResponse(boolean success, BigDecimal tariffRate,
//                               String hsCode, String countryCode, String message) {
//            this.success = success;
//            this.tariffRate = tariffRate;
//            this.hsCode = hsCode;
//            this.countryCode = countryCode;
//            this.message = message;
//            this.formattedRate = tariffRate != null ?
//                    tariffRate.toString() + " %" : null;
//        }
//
//        public static TariffResponse success(BigDecimal rate, String hsCode, String countryCode) {
//            return new TariffResponse(true, rate, hsCode, countryCode,
//                    "Tariff rate found successfully");
//        }
//
//        public static TariffResponse notFound(String message) {
//            return new TariffResponse(false, null, null, null, message);
//        }
//
//        public static TariffResponse error(String message) {
//            return new TariffResponse(false, null, null, null, message);
//        }
//
//        // Getters
//        public boolean isSuccess() { return success; }
//        public BigDecimal getTariffRate() { return tariffRate; }
//        public String getHsCode() { return hsCode; }
//        public String getCountryCode() { return countryCode; }
//        public String getMessage() { return message; }
//        public String getFormattedRate() { return formattedRate; }
//    }
}