package de.effigenix.shared.common;

import org.junit.jupiter.api.Test;

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

class CountryTest {

    @Test
    void shouldCreateValidCountry() {
        var country = new Country("DE", "Deutschland");
        assertThat(country.code()).isEqualTo("DE");
        assertThat(country.name()).isEqualTo("Deutschland");
    }

    @Test
    void shouldRejectNullCode() {
        assertThatThrownBy(() -> new Country(null, "Test"))
                .isInstanceOf(IllegalArgumentException.class)
                .hasMessageContaining("2 uppercase letters");
    }

    @Test
    void shouldRejectLowercaseCode() {
        assertThatThrownBy(() -> new Country("de", "Test"))
                .isInstanceOf(IllegalArgumentException.class)
                .hasMessageContaining("2 uppercase letters");
    }

    @Test
    void shouldRejectThreeLetterCode() {
        assertThatThrownBy(() -> new Country("DEU", "Test"))
                .isInstanceOf(IllegalArgumentException.class)
                .hasMessageContaining("2 uppercase letters");
    }

    @Test
    void shouldRejectNullName() {
        assertThatThrownBy(() -> new Country("DE", null))
                .isInstanceOf(IllegalArgumentException.class)
                .hasMessageContaining("blank");
    }

    @Test
    void shouldRejectBlankName() {
        assertThatThrownBy(() -> new Country("DE", "  "))
                .isInstanceOf(IllegalArgumentException.class)
                .hasMessageContaining("blank");
    }

    @Test
    void shouldRejectEmptyCode() {
        assertThatThrownBy(() -> new Country("", "Test"))
                .isInstanceOf(IllegalArgumentException.class)
                .hasMessageContaining("2 uppercase letters");
    }

    @Test
    void shouldRejectSingleLetterCode() {
        assertThatThrownBy(() -> new Country("A", "Test"))
                .isInstanceOf(IllegalArgumentException.class)
                .hasMessageContaining("2 uppercase letters");
    }

    @Test
    void shouldRejectCodeWithDigits() {
        assertThatThrownBy(() -> new Country("D1", "Test"))
                .isInstanceOf(IllegalArgumentException.class)
                .hasMessageContaining("2 uppercase letters");
    }

    @Test
    void shouldRejectMixedCaseCode() {
        assertThatThrownBy(() -> new Country("De", "Test"))
                .isInstanceOf(IllegalArgumentException.class)
                .hasMessageContaining("2 uppercase letters");
    }

    @Test
    void shouldRejectEmptyName() {
        assertThatThrownBy(() -> new Country("DE", ""))
                .isInstanceOf(IllegalArgumentException.class)
                .hasMessageContaining("blank");
    }
}
