import Foundation
import GRDB

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

nonisolated extension SmartPlaylist: FetchableRecord, MutablePersistableRecord {
    static let databaseTableName = "smart_playlists"

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

extension SmartPlaylist: PlaylistRepresentable {
    var isSmartPlaylist: Bool { true }
}

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