//
//  RichPresence.swift
//  SwordRPC
//
//  Created by Alejandro Alonso
//  Copyright © 2017 Alejandro Alonso. All rights reserved.
//

import Foundation

public struct RichButton: Encodable {
  public var label: String? = nil
  public var url: String? = nil
  
  public init() {}
}

public struct RichParty: Encodable {
  public var id: String? = nil
  public var max: Int? = nil
  public var size: Int? = nil
  
  enum CodingKeys: String, CodingKey {
    case id
    case size
  }
  
  public func encode(to encoder: Encoder) throws {
    var container = encoder.container(keyedBy: CodingKeys.self)
    try container.encodeIfPresent(self.id, forKey: .id)
    
    guard let max = self.max, let size = self.size else {
      return
    }
    
    try container.encode([size, max], forKey: .size)
  }
  
  public init() {}
}

public struct RichTimestamps: Encodable {
  public var end: Int? = nil
  public var start: Int? = nil
  
  public init() {}
}

public struct RichAssets: Encodable {
  public var largeImage: String? = nil
  public var largeText: String? = nil
  public var smallImage: String? = nil
  public var smallText: String? = nil
  
  enum CodingKeys: String, CodingKey {
    case largeImage = "large_image"
    case largeText = "large_text"
    case smallImage = "small_image"
    case smallText = "small_text"
  }
  
  public init() {}
}

public struct RichSecrets: Encodable {
  public var join: String? = nil
  public var match: String? = nil
  public var spectate: String? = nil
  
  public init() {}
}

public enum RichActivityType: Int, Encodable {
  case GAME = 0
  case STREAMING = 1
  case LISTENING = 2
  case WATCHING = 3
  case CUSTOM = 4
  case COMPETING = 5
}

public struct RichActivityEmoji: Encodable {
  public var name: String = ""
  public var id: String? = nil
  public var animated: Bool? = nil
  
  public init() {}
}

public struct RichPresence: Encodable {
  public var type: RichActivityType = .GAME
  public var url: String? = nil
  public var emoji: RichActivityEmoji? = nil
  public var assets = RichAssets()
  public var details = ""
  public var instance = true
  public var party = RichParty()
  public var secrets: RichSecrets? = nil
  public var state = ""
  public var timestamps = RichTimestamps()
  public var buttons: [RichButton]? = nil
  public init() {}
}
