// Copyright (C) 2024 Philipp Hofer
//
// Licensed under the EUPL, Version 1.2 or - as soon they will be approved by
// the European Commission - subsequent versions of the EUPL (the "Licence").
// You may not use this work except in compliance with the Licence.
//
// You should have received a copy of the European Union Public License along
// with this program.  If not, you may obtain a copy of the Licence at:
// <https://joinup.ec.europa.eu/software/page/eupl>
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the Licence is distributed on an "AS IS" basis,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the Licence for the specific language governing permissions and
// limitations under the Licence.

pub fn contains_without_unter(classifier_name: &str, instance_name: &str) -> bool {
    instance_name
        .to_lowercase()
        .contains(&classifier_name.to_lowercase())
        && !instance_name.to_lowercase().contains("unter")
}

pub fn always_true(_: &str, _: &str) -> bool {
    true
}

pub fn contains(classifier_name: &str, instance_name: &str) -> bool {
    instance_name
        .to_lowercase()
        .contains(&classifier_name.to_lowercase())
}

pub fn contains_case_sensitive(classifier_name: &str, instance_name: &str) -> bool {
    instance_name.contains(classifier_name)
}

pub fn starts_with_roman_number(_: &str, s: &str) -> bool {
    // Define the prefixes for Roman numerals.
    let roman_prefixes = [
        "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX", "X", "XI", "XII", "XIII", "XIV",
        "XV", "XVI", "XVII", "XVIII", "XIX", "XX",
    ];

    // Check if the string starts with one of the Roman numeral prefixes followed by a period.
    roman_prefixes
        .iter()
        .any(|&prefix| s.starts_with(&(prefix.to_string() + ".")))
}

pub fn contains_at_start(_classifier_name: &str, instance_name: &str) -> bool {
    !instance_name.is_empty() && instance_name.starts_with('@')
}

pub fn starts_with_number(_classifier_name: &str, instance_name: &str) -> bool {
    matches!(instance_name.trim().as_bytes().first(), Some(c) if c.is_ascii_digit())
}

pub fn starts_with_letter(_classifier_name: &str, instance_name: &str) -> bool {
    instance_name.starts_with(|c: char| c.is_ascii_lowercase())
        && (instance_name.chars().nth(1) == Some('.') || instance_name.chars().nth(1) == Some(')'))
}

pub fn starts_with_uppercaseletter(_classifier_name: &str, instance_name: &str) -> bool {
    instance_name.starts_with(|c: char| c.is_ascii_uppercase())
        && !instance_name.starts_with('I')
        && (instance_name.chars().nth(1) == Some('.') || instance_name.chars().nth(1) == Some(')'))
}

pub fn starts_with_dash(_classifier_name: &str, instance_name: &str) -> bool {
    instance_name.starts_with('-') && (instance_name.chars().nth(1) == Some(' '))
}
