import Foundation

public protocol PlaylistDisplayable {
    var id: String { get }
    var title: String { get }
    var imageUrl: String? { get }
    var totalResults: Int { get }
    var authorName: String? { get }
    var authorHandle: String? { get }
    var authorAvatar: String? { get }
    var isPublic: Bool { get }
    var isOwned: Bool { get }
    var canShare: Bool { get }
    var canManage: Bool { get }
    var showAuthorInfo: Bool { get }
}

extension Playlist: PlaylistDisplayable {
    public var title: String { name }
    public var authorName: String? { userDisplayName }
    public var authorHandle: String? { userHandle }
    public var authorAvatar: String? { userAvatarImageUrl }
    public var canShare: Bool { true }
    public var canManage: Bool { isOwned }
    public var showAuthorInfo: Bool { true }
}

extension Genre: PlaylistDisplayable {
    public var title: String { name }
    public var imageUrl: String? { image }
    public var totalResults: Int { totalClipsCount }
    public var authorName: String? { nil }
    public var authorHandle: String? { nil }
    public var authorAvatar: String? { nil }
    public var isPublic: Bool { true }
    public var isOwned: Bool { false }
    public var canShare: Bool { false }
    public var canManage: Bool { false }
    public var showAuthorInfo: Bool { false }
}

extension PlaylistSection: PlaylistDisplayable {
    public var imageUrl: String? { items.first?.largeImageUrl }
    public var totalResults: Int { 0 }
    public var authorName: String? { nil }
    public var authorHandle: String? { nil }
    public var authorAvatar: String? { nil }
    public var isPublic: Bool { true }
    public var isOwned: Bool { false }
    public var canShare: Bool { false }
    public var canManage: Bool { false }
    public var showAuthorInfo: Bool { false }
}

// Lets us display a skeleton with a title and image while the clip list
// loads, if we're coming from a Playlist tile elsewhere (ex. Hooks tab).
public struct PlaylistPreview: PlaylistDisplayable {
    public let id: String
    public let _title: String?
    public let imageUrl: String?
    
    public var title: String { _title ?? "" }
    public var totalResults: Int { 0 }
    public var authorName: String? { nil }
    public var authorHandle: String? { nil }
    public var authorAvatar: String? { nil }
    public var isPublic: Bool { false }
    public var isOwned: Bool { false }
    public var canShare: Bool { !id.isEmpty }
    public var canManage: Bool { false }
    public var showAuthorInfo: Bool { false }
    
    public init(id: String, title: String?, imageUrl: String?) {
        self.id = id
        self._title = title
        self.imageUrl = imageUrl
    }
}

