///|
/// Represents a video file.
pub struct Video {
  file_id : String
  file_unique_id : String
  width : Int
  height : Int
  duration : Int
  thumbnail : PhotoSize?
  cover : Array[PhotoSize]?
  start_timestamp : Int?
  file_name : String?
  mime_type : String?
  file_size : Int64?
} derive(Show, Eq)

///|
/// Creates a new [Video].
pub fn Video::new(
  file_id~ : String,
  file_unique_id~ : String,
  width~ : Int,
  height~ : Int,
  duration~ : Int,
  thumbnail? : PhotoSize,
  cover? : Array[PhotoSize],
  start_timestamp? : Int,
  file_name? : String,
  mime_type? : String,
  file_size? : Int64,
) -> Video {
  {
    file_id,
    file_unique_id,
    width,
    height,
    duration,
    thumbnail,
    cover,
    start_timestamp,
    file_name,
    mime_type,
    file_size,
  }
}

///|
pub impl ToJson for Video with to_json(self) {
  let object : Map[String, Json] = {
    "file_id": self.file_id.to_json(),
    "file_unique_id": self.file_unique_id.to_json(),
    "width": self.width.to_json(),
    "height": self.height.to_json(),
    "duration": self.duration.to_json(),
  }
  if self.thumbnail is Some(v) {
    object["thumbnail"] = v.to_json()
  }
  if self.cover is Some(v) {
    object["cover"] = v.to_json()
  }
  if self.start_timestamp is Some(v) {
    object["start_timestamp"] = v.to_json()
  }
  if self.file_name is Some(v) {
    object["file_name"] = v.to_json()
  }
  if self.mime_type is Some(v) {
    object["mime_type"] = v.to_json()
  }
  if self.file_size is Some(v) {
    object["file_size"] = int64_to_json(v)
  }
  object.to_json()
}

///|
pub impl @json.FromJson for Video with from_json(json, path) {
  guard json is Object(object) else {
    raise @json.JsonDecodeError((path, "Expected object for Video"))
  }
  let file_id : String = @json.from_json(object["file_id"], path~)
  let file_unique_id : String = @json.from_json(object["file_unique_id"], path~)
  let width : Int = @json.from_json(object["width"], path~)
  let height : Int = @json.from_json(object["height"], path~)
  let duration : Int = @json.from_json(object["duration"], path~)
  let thumbnail : PhotoSize? = if object.get("thumbnail") is Some(v) {
    Some(@json.from_json(v, path~))
  } else {
    None
  }
  let cover : Array[PhotoSize]? = if object.get("cover") is Some(v) {
    Some(@json.from_json(v, path~))
  } else {
    None
  }
  let start_timestamp : Int? = if object.get("start_timestamp") is Some(v) {
    Some(@json.from_json(v, path~))
  } else {
    None
  }
  let file_name : String? = if object.get("file_name") is Some(v) {
    Some(@json.from_json(v, path~))
  } else {
    None
  }
  let mime_type : String? = if object.get("mime_type") is Some(v) {
    Some(@json.from_json(v, path~))
  } else {
    None
  }
  let file_size : Int64? = if object.get("file_size") is Some(v) {
    Some(int64_from_json(v, path))
  } else {
    None
  }
  {
    file_id,
    file_unique_id,
    width,
    height,
    duration,
    thumbnail,
    cover,
    start_timestamp,
    file_name,
    mime_type,
    file_size,
  }
}