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.Map;

/**
 * Twilio SMS/MMS 어댑터 (mall.sms.provider=twilio).
 * 키는 환경변수 TWILIO_ACCOUNT_SID/TWILIO_AUTH_TOKEN/TWILIO_FROM만. 키 없으면 비활성.
 */
@Component
@ConditionalOnProperty(name = "mall.sms.provider", havingValue = "twilio")
public class TwilioSmsSender implements SmsSender {

    @Value("${TWILIO_ACCOUNT_SID:}")
    private String accountSid;
    @Value("${TWILIO_AUTH_TOKEN:}")
    private String authToken;
    @Value("${TWILIO_FROM:}")
    private String fromNumber;

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

    @Override
    public Map<String, Object> sendSms(String toPhone, String body) {
        requireKey();
        throw new UnsupportedOperationException("ERR-SMS-IMPL: Twilio SMS 실연동은 운영 배포 시 구현");
    }

    @Override
    public Map<String, Object> sendMms(String toPhone, String body, String mediaUrl) {
        requireKey();
        throw new UnsupportedOperationException("ERR-SMS-IMPL: Twilio MMS 실연동은 운영 배포 시 구현");
    }

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