package cloud.nstart.terravault.ordinis.restapi.service.reference;

import org.junit.jupiter.api.Test;

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

class OrphanReferenceScannerTest {

  @Test
  void parsesValidRef() {
    var p = OrphanReferenceScanner.parseRef("satellite_type.code");
    assertThat(p.dictName()).isEqualTo("satellite_type");
    assertThat(p.fieldName()).isEqualTo("code");
  }

  @Test
  void rejectsEmpty() {
    assertThatThrownBy(() -> OrphanReferenceScanner.parseRef(""))
        .isInstanceOf(IllegalArgumentException.class);
    assertThatThrownBy(() -> OrphanReferenceScanner.parseRef(null))
        .isInstanceOf(IllegalArgumentException.class);
  }

  @Test
  void rejectsMissingDot() {
    assertThatThrownBy(() -> OrphanReferenceScanner.parseRef("noDot"))
        .hasMessageContaining("dict.field");
  }

  @Test
  void rejectsLeadingTrailingDot() {
    assertThatThrownBy(() -> OrphanReferenceScanner.parseRef(".field"))
        .hasMessageContaining("dict.field");
    assertThatThrownBy(() -> OrphanReferenceScanner.parseRef("dict."))
        .hasMessageContaining("dict.field");
  }
}
