30 lines
891 B
Swift
30 lines
891 B
Swift
import Foundation
|
|
|
|
public protocol SunoOutputValidating: Sendable {
|
|
func validate(_ output: CompiledSunoOutput) throws
|
|
}
|
|
|
|
public enum SunoOutputValidationError: Error, Equatable, LocalizedError, Sendable {
|
|
case missingContent
|
|
|
|
public var errorDescription: String? {
|
|
switch self {
|
|
case .missingContent:
|
|
return "Add lyrics or a style prompt before sending the song to Suno."
|
|
}
|
|
}
|
|
}
|
|
|
|
public struct CompiledSunoOutputValidator: SunoOutputValidating {
|
|
public init() {}
|
|
|
|
public func validate(_ output: CompiledSunoOutput) throws {
|
|
let lyrics = output.lyricsText.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
let style = output.stylePrompt.trimmingCharacters(in: .whitespacesAndNewlines)
|
|
|
|
guard !lyrics.isEmpty || !style.isEmpty else {
|
|
throw SunoOutputValidationError.missingContent
|
|
}
|
|
}
|
|
}
|