package com.zioinfo.mall.gateway;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Map;

/**
 * Smarty(SmartyStreets) 주소 검증 어댑터 (mall.address.provider=smarty).
 * 키는 환경변수 SMARTY_AUTH_ID/SMARTY_AUTH_TOKEN만. 키 없으면 비활성.
 */
@Component
@ConditionalOnProperty(name = "mall.address.provider", havingValue = "smarty")
public class SmartyVerifier implements AddressVerifier {

    @Value("${SMARTY_AUTH_ID:}")
    private String authId;
    @Value("${SMARTY_AUTH_TOKEN:}")
    private String authToken;

    private void requireKey() {
        if (authId == null || authId.isBlank() || authToken == null || authToken.isBlank()) {
            throw new IllegalStateException("ERR-ADDR-CONFIG: SMARTY 인증정보 미설정");
        }
    }

    @Override
    public Map<String, Object> verify(String address, String zip) {
        requireKey();
        throw new UnsupportedOperationException("ERR-ADDR-IMPL: Smarty 실연동은 운영 배포 시 구현");
    }

    @Override
    public Map<String, Object> route(List<String> addresses, String origin) {
        requireKey();
        throw new UnsupportedOperationException("ERR-ADDR-IMPL: Smarty는 라우팅 미지원 — Google 사용");
    }

    @Override
    public String provider() {
        return "smarty";
    }
}
