Enforce user locks for AI updates

This commit is contained in:
diyaa
2026-09-13 21:20:57 +02:00
parent a39bdbe6fc
commit ae88c6e533
15 changed files with 507 additions and 59 deletions
@@ -0,0 +1,42 @@
import Foundation
public enum SongProjectUpdateScope: String, CaseIterable, Codable, Equatable, Hashable, Sendable {
case duration
case genres
case instruments
case vocals
case languages
case lyrics
case structure
case arrangement
case musicalParameters
case emotionalArc
case productionDirections
case sunoOutput
}
public struct SongProjectUserLocks: Codable, Equatable, Sendable {
public var scopes: [SongProjectUpdateScope]
public init(scopes: [SongProjectUpdateScope] = []) {
self.scopes = Self.uniqueScopes(scopes)
}
public func contains(_ scope: SongProjectUpdateScope) -> Bool {
scopes.contains(scope)
}
public mutating func insert(_ scope: SongProjectUpdateScope) {
guard !contains(scope) else { return }
scopes.append(scope)
}
public mutating func remove(_ scope: SongProjectUpdateScope) {
scopes.removeAll { $0 == scope }
}
private static func uniqueScopes(_ scopes: [SongProjectUpdateScope]) -> [SongProjectUpdateScope] {
var seen = Set<SongProjectUpdateScope>()
return scopes.filter { seen.insert($0).inserted }
}
}