package com.ai.trackwalker.capability.uav;

import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ResponseStatusException;

import java.util.List;

@Component
public class UavVendorAdapterRegistry {
    private final List<UavVendorAdapter> adapters;

    public UavVendorAdapterRegistry(List<UavVendorAdapter> adapters) {
        this.adapters = adapters;
    }

    public UavVendorAdapter require(String vendorCode) {
        return adapters.stream()
                .filter(adapter -> adapter.vendorCode().equalsIgnoreCase(vendorCode))
                .findFirst()
                .orElseThrow(() -> new ResponseStatusException(
                        HttpStatus.SERVICE_UNAVAILABLE,
                        vendorCode + " 生产适配器尚未启用：需要正式 SDK/API、授权、测试环境和设备资料"
                ));
    }
}
