from .types import SERVICE_CONSTRAINTS, ValidationResult


def validate_import_key(key: str, service: str) -> ValidationResult:
    """
    Validates the key according to the `service` rules
    """
    # Trim spaces from both sides.
    formatted_key = key.strip()
    if service in SERVICE_CONSTRAINTS:
        errors = SERVICE_CONSTRAINTS[service](formatted_key, [])
    else:
        errors = ["Not a valid service."]

    return ValidationResult[str](is_valid=not errors, errors=errors, modified_result=formatted_key)
