package com.zioinfo.mall.gateway;

import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;

import java.util.LinkedHashMap;
import java.util.Map;
import java.util.UUID;

/** Mock SMS/MMS 발송기 (기본). 외부 호출 0 — 로그만 남기고 성공 반환. */
@Slf4j
@Component
@ConditionalOnProperty(name = "mall.sms.provider", havingValue = "mock", matchIfMissing = true)
public class MockSmsSender implements SmsSender {

    @Override
    public Map<String, Object> sendSms(String toPhone, String body) {
        log.info("[MOCK-SMS] to={} body={}", mask(toPhone), body);
        return result("SMS");
    }

    @Override
    public Map<String, Object> sendMms(String toPhone, String body, String mediaUrl) {
        log.info("[MOCK-MMS] to={} media={} body={}", mask(toPhone), mediaUrl, body);
        return result("MMS");
    }

    private Map<String, Object> result(String type) {
        Map<String, Object> out = new LinkedHashMap<>();
        out.put("provider", "mock");
        out.put("messageId", "MOCK-" + type + "-" + UUID.randomUUID().toString().substring(0, 10));
        out.put("status", "SENT");
        return out;
    }

    private String mask(String phone) {
        if (phone == null || phone.length() < 4) return "****";
        return "***" + phone.substring(phone.length() - 4);
    }

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