import Foundation
import GRDB

nonisolated struct Playlist: Codable, Identifiable, Equatable, Hashable, Sendable {
    var id: Int64?
    var name: String
    var createdAt: Date
}

nonisolated extension Playlist: FetchableRecord, MutablePersistableRecord {
    static let databaseTableName = "playlists"

    mutating func didInsert(_ inserted: InsertionSuccess) {
        id = inserted.rowID
    }
}

extension Playlist: PlaylistRepresentable {
    var isSmartPlaylist: Bool { false }
}

#if DEBUG
extension Playlist {
    static func fixture(
        id: Int64? = nil,
        name: String = "Test Playlist",
        createdAt: Date = Date()
    ) -> Playlist {
        Playlist(id: id, name: name, createdAt: createdAt)
    }
}
#endif
