//
// Generated by SwagGen
// https://github.com/yonaskolb/SwagGen
//

import Foundation
import JSONUtilities

public class Entitlement: OfferRights {

    /** The date of activation. If no date is defined the entitlement has not be activated. */
    public var activationDate: Date?

    /** The classification of the entitled item. */
    public var classification: ClassificationSummary?

    /** The date the entitlement was created. */
    public var creationDate: Date?

    /** The date the entitlement expires. */
    public var expirationDate: Date?

    /** The id of the item this entitlement is for. */
    public var itemId: String?

    /** The type of item this entitlement is for. */
    public var itemType: ItemType?

    /** The duration of the entitled media. */
    public var mediaDuration: Int?

    /** How many times the media has been played. */
    public var playCount: Int?

    /** How many more downloads of this media are available. */
    public var remainingDownloads: Int?

    public init(deliveryType: DeliveryType, scopes: [String], resolution: Resolution, ownership: Ownership, exclusionRules: [ExclusionRule]? = nil, maxDownloads: Int? = nil, maxPlays: Int? = nil, playPeriod: Int? = nil, rentalPeriod: Int? = nil, activationDate: Date? = nil, classification: ClassificationSummary? = nil, creationDate: Date? = nil, expirationDate: Date? = nil, itemId: String? = nil, itemType: ItemType? = nil, mediaDuration: Int? = nil, playCount: Int? = nil, remainingDownloads: Int? = nil) {
        self.activationDate = activationDate
        self.classification = classification
        self.creationDate = creationDate
        self.expirationDate = expirationDate
        self.itemId = itemId
        self.itemType = itemType
        self.mediaDuration = mediaDuration
        self.playCount = playCount
        self.remainingDownloads = remainingDownloads
        super.init(deliveryType: deliveryType, scopes: scopes, resolution: resolution, ownership: ownership, exclusionRules: exclusionRules, maxDownloads: maxDownloads, maxPlays: maxPlays, playPeriod: playPeriod, rentalPeriod: rentalPeriod)
    }

    public required init(jsonDictionary: JSONDictionary) throws {
        activationDate = jsonDictionary.json(atKeyPath: "activationDate")
        classification = jsonDictionary.json(atKeyPath: "classification")
        creationDate = jsonDictionary.json(atKeyPath: "creationDate")
        expirationDate = jsonDictionary.json(atKeyPath: "expirationDate")
        itemId = jsonDictionary.json(atKeyPath: "itemId")
        itemType = jsonDictionary.json(atKeyPath: "itemType")
        mediaDuration = jsonDictionary.json(atKeyPath: "mediaDuration")
        playCount = jsonDictionary.json(atKeyPath: "playCount")
        remainingDownloads = jsonDictionary.json(atKeyPath: "remainingDownloads")
        try super.init(jsonDictionary: jsonDictionary)
    }

    public override func encode() -> JSONDictionary {
        var dictionary: JSONDictionary = [:]
        if let activationDate = activationDate?.encode() {
            dictionary["activationDate"] = activationDate
        }
        if let classification = classification?.encode() {
            dictionary["classification"] = classification
        }
        if let creationDate = creationDate?.encode() {
            dictionary["creationDate"] = creationDate
        }
        if let expirationDate = expirationDate?.encode() {
            dictionary["expirationDate"] = expirationDate
        }
        if let itemId = itemId {
            dictionary["itemId"] = itemId
        }
        if let itemType = itemType?.encode() {
            dictionary["itemType"] = itemType
        }
        if let mediaDuration = mediaDuration {
            dictionary["mediaDuration"] = mediaDuration
        }
        if let playCount = playCount {
            dictionary["playCount"] = playCount
        }
        if let remainingDownloads = remainingDownloads {
            dictionary["remainingDownloads"] = remainingDownloads
        }
        let superDictionary = super.encode()
        for (key, value) in superDictionary {
            dictionary[key] = value
        }
        return dictionary
    }
}
