package com.cloudhandson.vpdbackoffice.service;

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

import java.util.List;
import org.junit.jupiter.api.Test;

class GameCatalogVectorServiceTest {

  private static final GameCatalogVectorService.GameCandidate CATALOG_GAME =
      new GameCatalogVectorService.GameCandidate(
          "GAME_KEY",
          "GAME_ID",
          "GME",
          "Catalog Game",
          "GME Catalog Game 카탈로그게임",
          0.31
      );

  @Test
  void acceptsCandidateWhoseCatalogIdentityContainsTheExtractedMention() {
    var match = GameCatalogVectorService.selectMatchedCandidate(
        "카탈로그 게임", List.of(CATALOG_GAME));

    assertThat(match).contains(CATALOG_GAME);
  }

  @Test
  void rejectsNearestVectorCandidateWithoutCatalogIdentityMatch() {
    var match = GameCatalogVectorService.selectMatchedCandidate(
        "Unknown title", List.of(CATALOG_GAME));

    assertThat(match).isEmpty();
  }

  @Test
  void choosesClosestCandidateAmongIdentityMatches() {
    var farther = new GameCatalogVectorService.GameCandidate(
        "GAME_KEY_2",
        "GAME_ID_2",
        "GM2",
        "Catalog Game Plus",
        "Catalog Game Plus",
        0.44
    );

    var match = GameCatalogVectorService.selectMatchedCandidate(
        "Catalog Game", List.of(farther, CATALOG_GAME));

    assertThat(match).contains(CATALOG_GAME);
  }
}
