diff --git a/Sources/DiscogsService/Internal/Validation Rules/NotEmptyValidationRule.swift b/Sources/DiscogsService/Internal/Validation Rules/NotEmptyValidationRule.swift new file mode 100644 index 000000000..dbcbfbfea --- /dev/null +++ b/Sources/DiscogsService/Internal/Validation Rules/NotEmptyValidationRule.swift @@ -0,0 +1,38 @@ +// ===----------------------------------------------------------------------=== +// +// This source file is part of the DiscogsService open source project +// +// Copyright (c) 2025 Röck+Cöde VoF. and the DiscogsService project authors +// Licensed under Apache license v2.0 +// +// See LICENSE for license information +// See CONTRIBUTORS for the list of DiscogsService project authors +// +// SPDX-License-Identifier: Apache-2.0 +// +// ===----------------------------------------------------------------------=== + +/// A validation rule type that checks whether an input is empty or not. +struct NotEmptyValidationRule: InputValidationRule { + + // MARK: Functions + + func validate(_ input: String?) throws -> Bool { + guard let input else { + return false + } + guard !input.isEmpty else { + throw InputValidationError.inputIsEmpty + } + + return true + } + +} + +// MARK: - Constants + +extension InputValidationRule where Self == NotEmptyValidationRule { + /// A validation rule that checks whether an input is empty or not. + static var notEmpty: Self { .init() } +}