package com.starry.admin.api;

import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.WxMpTemplateMsgService;
import org.mockito.Mockito;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Profile;

/**
 * Provides stubbed WeChat MP services in the apitest profile so integration tests never hit external APIs.
 */
@TestConfiguration
@Profile("apitest")
public class MockWxMpServiceConfig {

    @Bean
    @Primary
    public WxMpService wxMpService() {
        WxMpService service = mock(WxMpService.class, Mockito.RETURNS_DEEP_STUBS);
        WxMpTemplateMsgService templateMsgService = mock(WxMpTemplateMsgService.class);
        when(service.getTemplateMsgService()).thenReturn(templateMsgService);
        when(service.switchoverTo(Mockito.anyString())).thenReturn(service);
        when(service.switchover(Mockito.anyString())).thenReturn(true);
        return service;
    }
}
