package com.ga.external;

import com.ga.common.adapter.bank.BankTransferRequest;
import com.ga.common.adapter.message.MessageChannel;
import com.ga.common.adapter.message.MessageRequest;
import com.ga.common.adapter.push.PushRequest;
import com.ga.external.bank.KftcBankTransferAdapter;
import com.ga.external.bank.KftcProperties;
import com.ga.external.message.ToastMessageAdapter;
import com.ga.external.message.ToastProperties;
import com.ga.external.push.FcmProperties;
import com.ga.external.push.FcmPushAdapter;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;

import java.math.BigDecimal;

import static org.assertj.core.api.Assertions.assertThatThrownBy;

/**
 * 실 KFTC/Toast 어댑터의 fail-fast 동작 검증.
 * 자격증명(키/토큰)이 비어 있으면 외부 호출 전에 IllegalStateException 으로 즉시 차단되어야 한다.
 * (실 HTTP 는 운영 키 주입 후 테스트베드에서 검증)
 */
class AdapterFailFastTest {

    @Test
    @DisplayName("Toast SMS: 설정 누락 시 fail-fast")
    void toastSms_failFast() {
        ToastMessageAdapter adapter = new ToastMessageAdapter(new ToastProperties());
        MessageRequest req = MessageRequest.builder()
                .channel(MessageChannel.SMS)
                .phoneNumber("010-1234-5678")
                .content("테스트")
                .build();
        assertThatThrownBy(() -> adapter.send(req))
                .isInstanceOf(IllegalStateException.class)
                .hasMessageContaining("app.adapter.toast");
    }

    @Test
    @DisplayName("Toast 알림톡: templateCode 없으면 차단")
    void toastAlimtalk_requiresTemplate() {
        ToastProperties p = new ToastProperties();
        p.setAlimtalkAppKey("k");
        p.setAlimtalkSecretKey("s");
        p.setSenderKey("sk");
        ToastMessageAdapter adapter = new ToastMessageAdapter(p);
        MessageRequest req = MessageRequest.builder()
                .channel(MessageChannel.KAKAO)
                .phoneNumber("01012345678")
                .content("내용")
                .build();
        assertThatThrownBy(() -> adapter.send(req))
                .isInstanceOf(IllegalArgumentException.class)
                .hasMessageContaining("templateCode");
    }

    @Test
    @DisplayName("KFTC 입금이체: 토큰/약정계좌 누락 시 fail-fast")
    void kftc_failFast() {
        KftcBankTransferAdapter adapter = new KftcBankTransferAdapter(new KftcProperties());
        BankTransferRequest req = BankTransferRequest.builder()
                .withdrawRequestId(1L)
                .bankCode("097")
                .accountNo("1101230000678")
                .accountHolderName("홍길동")
                .amount(new BigDecimal("10000"))
                .memo("정산")
                .build();
        assertThatThrownBy(() -> adapter.requestTransfer(req))
                .isInstanceOf(IllegalStateException.class)
                .hasMessageContaining("app.adapter.kftc");
    }

    @Test
    @DisplayName("FCM 푸시: projectId/토큰 누락 시 fail-fast")
    void fcm_failFast() {
        FcmPushAdapter adapter = new FcmPushAdapter(new FcmProperties());
        PushRequest req = PushRequest.builder()
                .deviceToken("dummy-token")
                .title("제목").body("내용")
                .refType("WITHDRAW").refId(1L)
                .build();
        assertThatThrownBy(() -> adapter.send(req))
                .isInstanceOf(IllegalStateException.class)
                .hasMessageContaining("app.adapter.fcm");
    }
}
