package com.mosquito.project.integration;

import com.mosquito.project.security.IntrospectionResponse;
import com.mosquito.project.security.UserIntrospectionService;
import org.mockito.Mockito;
import org.springframework.boot.test.context.TestConfiguration;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Primary;

import java.time.Instant;
import java.util.List;

@TestConfiguration
class IntegrationTestConfig {

    @Bean
    @Primary
    UserIntrospectionService userIntrospectionService() {
        UserIntrospectionService service = Mockito.mock(UserIntrospectionService.class);
        IntrospectionResponse active = new IntrospectionResponse();
        active.setActive(true);
        active.setUserId("test-user");
        active.setTenantId("test-tenant");
        active.setRoles(List.of("test"));
        active.setScopes(List.of("api"));
        long now = Instant.now().getEpochSecond();
        active.setIat(now);
        active.setExp(now + 3600);
        active.setJti("test-jti");
        Mockito.when(service.introspect(Mockito.anyString())).thenReturn(active);
        return service;
    }
}
