package com.cloudhandson.vpdbackoffice.service;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.mockito.Mockito.mock;

import org.junit.jupiter.api.Test;
import org.springframework.jdbc.core.JdbcTemplate;
import java.util.List;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.doThrow;

class StructuredDataServiceTest {

  private final DataCatalog catalog = mock(DataCatalog.class);
  private final StructuredDataService service = new StructuredDataService(mock(JdbcTemplate.class), catalog);

  @Test
  void exposesOnlyTheSevenApprovedSmilegateStructuredTables() {
    when(catalog.objects()).thenReturn(List.of(
        new com.cloudhandson.vpdbackoffice.domain.structured.StructuredDataTable("sales", "COMN_SALES_TXN", "판매 거래", "게임 상품 판매 거래")));
    assertThat(service.tables())
        .extracting(table -> table.tableName())
        .containsExactly("COMN_SALES_TXN");
  }

  @Test
  void rejectsAnyTableOutsideTheServerSideAllowlist() {
    doThrow(new AppException("선택할 수 없는 카탈로그 객체입니다."))
        .when(catalog).require("security-audit-log");
    assertThatThrownBy(() -> service.requireTable("security-audit-log"))
        .isInstanceOf(AppException.class)
        .hasMessage("선택할 수 없는 카탈로그 객체입니다.");
  }
}
