/*
 * Copyright (C) 2026  Tim Zimmermann <tim@aglais.org>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

package org.aglais.zms.gbif;

import org.junit.jupiter.api.Test;

import java.io.IOException;

import static org.junit.jupiter.api.Assertions.*;

/**
 * Integration testcases for {@link GBIFAPI}
 */
public class GBIFAPIIT {

    private static final String TEST_SPECIES = "Aglais io";
    private static final int TEST_SPECIES_KEY = 4535827;

    @Test
    public void testSpeciesMatch() throws IOException {
        GBIFSpeciesMatch speciesMatch = GBIFAPI.matchSpecies(TEST_SPECIES);

        assertNotNull(speciesMatch);
        assertEquals(TEST_SPECIES_KEY, speciesMatch.usageKey());
        assertEquals("Aglais io (Linnaeus, 1758)", speciesMatch.scientificName());
        assertEquals(TEST_SPECIES, speciesMatch.canonicalName());
        assertNotNull(speciesMatch.rank());
        assertNotNull(speciesMatch.status());
        assertEquals(99, speciesMatch.confidence());
        assertEquals("EXACT", speciesMatch.matchType());
        assertEquals("Animalia", speciesMatch.kingdom());
        assertEquals("Arthropoda", speciesMatch.phylum());
        assertEquals("Lepidoptera", speciesMatch.order());
        assertEquals("Nymphalidae", speciesMatch.family());
        assertEquals("Aglais", speciesMatch.genus());
        assertEquals(TEST_SPECIES, speciesMatch.species());
        assertFalse(speciesMatch.synonym());
    }

    @Test
    public void testIUCNRedListCategory() throws IOException {
        GBIFSpeciesIUCNRedListCategory iucnRedListCategory = GBIFAPI.getSpeciesIUCNRedListCategory(TEST_SPECIES_KEY);

        assertNotNull(iucnRedListCategory);
        assertNotNull(iucnRedListCategory.category());
        assertNotNull(iucnRedListCategory.scientificName());
        assertNotNull(iucnRedListCategory.taxonomicStatus());
        assertNotNull(iucnRedListCategory.code());
        assertEquals(2, iucnRedListCategory.code().length());
    }

}
