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;

/**
 * SendGrid 이메일 어댑터 (mall.email.provider=sendgrid).
 * 키는 환경변수 SENDGRID_API_KEY만. 키 없으면 비활성.
 */
@Component
@ConditionalOnProperty(name = "mall.email.provider", havingValue = "sendgrid")
public class SendGridEmailSender implements EmailSender {

    @Value("${SENDGRID_API_KEY:}")
    private String apiKey;

    @Override
    public Map<String, Object> send(String toEmail, String subject, String htmlBody) {
        if (apiKey == null || apiKey.isBlank()) {
            throw new IllegalStateException("ERR-EMAIL-CONFIG: SENDGRID_API_KEY 미설정");
        }
        throw new UnsupportedOperationException("ERR-EMAIL-IMPL: SendGrid 실연동은 운영 배포 시 구현");
    }

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