// Generated from WebIDL - DO NOT EDIT
// Source: @webref/idl/content-index

///|
/// ContentCategory enum
pub(all) enum ContentCategory {
  Empty
  Homepage
  Article
  Video
  Audio
} derive(Eq, Show)

///|
/// Convert to string value
pub fn ContentCategory::to_string(self : ContentCategory) -> String {
  match self {
    ContentCategory::Empty => ""
    ContentCategory::Homepage => "homepage"
    ContentCategory::Article => "article"
    ContentCategory::Video => "video"
    ContentCategory::Audio => "audio"
  }
}

///|
/// Parse from string value
pub fn ContentCategory::from_string(s : String) -> ContentCategory? {
  match s {
    "" => Some(ContentCategory::Empty)
    "homepage" => Some(ContentCategory::Homepage)
    "article" => Some(ContentCategory::Article)
    "video" => Some(ContentCategory::Video)
    "audio" => Some(ContentCategory::Audio)
    _ => None
  }
}

///|
/// ContentDescription dictionary
pub(all) struct ContentDescription {
  id : String
  title : String
  description : String
  category : ContentCategory?
  icons : Array[ImageResource]?
  url : String
}

///|
/// Create a new ContentDescription with default values
pub fn ContentDescription::default() -> ContentDescription {
  ContentDescription::{
    id: "",
    title: "",
    description: "",
    category: None,
    icons: None,
    url: "",
  }
}

///|
extern "js" fn ContentDescription::to_js_ffi(
  self : ContentDescription,
) -> JsValue =
  #| (self) => ({
  #|   id: self.id,
  #|   title: self.title,
  #|   description: self.description,
  #|   category: ((() => { const v = self.category; if (v === undefined) return undefined; return ['', 'homepage', 'article', 'video', 'audio'][v]; })()),
  #|   icons: ((() => { const v = self.icons; if (v === undefined || v.$tag !== 1) return undefined; return v._0; })()),
  #|   url: self.url
  #| })

///|
/// Convert to JsValue
pub fn ContentDescription::to_js(self : ContentDescription) -> JsValue {
  ContentDescription::to_js_ffi(self)
}

///|
extern "js" fn ContentDescription::from_js_ffi(
  value : JsValue,
) -> ContentDescription =
  #| (v) => ({
  #|   id: v.id,
  #|   title: v.title,
  #|   description: v.description,
  #|   category: (v.category === undefined ? undefined : ['', 'homepage', 'article', 'video', 'audio'].indexOf(v.category)),
  #|   icons: (v.icons === undefined ? { $tag: 0 } : { $tag: 1, _0: v.icons }),
  #|   url: v.url
  #| })

///|
/// Convert from JsValue
pub fn ContentDescription::from_js(value : JsValue) -> ContentDescription {
  ContentDescription::from_js_ffi(value)
}

///|
/// ContentIndexEventInit dictionary
pub(all) struct ContentIndexEventInit {
  id : String
}

///|
/// Create a new ContentIndexEventInit with default values
pub fn ContentIndexEventInit::default() -> ContentIndexEventInit {
  ContentIndexEventInit::{ id: "" }
}

///|
extern "js" fn ContentIndexEventInit::to_js_ffi(
  self : ContentIndexEventInit,
) -> JsValue =
  #| (self) => ({
  #|   id: self.id
  #| })

///|
/// Convert to JsValue
pub fn ContentIndexEventInit::to_js(self : ContentIndexEventInit) -> JsValue {
  ContentIndexEventInit::to_js_ffi(self)
}

///|
extern "js" fn ContentIndexEventInit::from_js_ffi(
  value : JsValue,
) -> ContentIndexEventInit =
  #| (v) => ({
  #|   id: v.id
  #| })

///|
/// Convert from JsValue
pub fn ContentIndexEventInit::from_js(value : JsValue) -> ContentIndexEventInit {
  ContentIndexEventInit::from_js_ffi(value)
}

///|
/// ContentIndex interface
pub type ContentIndex

///|
pub extern "js" fn ContentIndex::to_js_value(self : ContentIndex) -> JsValue =
  #| (self) => self

///|
/// Cast JsValue to ContentIndex (unchecked)
pub extern "js" fn ContentIndex::from_js_value(v : JsValue) -> ContentIndex =
  #| (v) => v

///|
/// Safely cast JsValue to ContentIndex (checked with instanceof)
pub extern "js" fn ContentIndex::from_js_value_opt(
  v : JsValue,
) -> ContentIndex? =
  #| (v) => (v instanceof ContentIndex) ? { $tag: 1, _0: v } : { $tag: 0 }

///|
/// Safely cast JsValue to ContentIndex (checked with instanceof)
pub extern "js" fn JsValue::as_content_index(self : JsValue) -> ContentIndex? =
  #| (self) => (self instanceof ContentIndex) ? { $tag: 1, _0: self } : { $tag: 0 }

///|
/// Cast JsValue to ContentIndex (unchecked)
pub extern "js" fn JsValue::to_content_index(self : JsValue) -> ContentIndex =
  #| (self) => self

///|
/// Error type for throwing methods
pub(all) enum ContentIndexAddError {
  TypeError(JsError)
  OtherError(JsError)
} derive(Show)

///|
extern "js" fn ContentIndex::add_ffi(
  self : ContentIndex,
  description : JsValue,
) -> Promise[Result[Unit, ContentIndexAddError]] =
  #| (self, description) => self.add(description).then(r => ({ $tag: 1, _0: undefined })).catch(e => ({ $tag: 0, _0: (() => { const n = (e && e.name) || ''; if (n === 'TypeError') return { $tag: 0, _0: e }; return { $tag: 1, _0: e }; })() }))

///|
pub fn ContentIndex::add(
  self : ContentIndex,
  description : ContentDescription,
) -> Promise[Result[Unit, ContentIndexAddError]] {
  ContentIndex::add_ffi(self, description.to_js())
}

///|
pub extern "js" fn ContentIndex::delete(
  self : ContentIndex,
  id : String,
) -> Promise[Unit] =
  #| (self, id) => self.delete(id)

///|
pub extern "js" fn ContentIndex::get_all(
  self : ContentIndex,
) -> Promise[Array[ContentDescription]] =
  #| (self) => self.getAll()

///|
/// ContentIndexEvent interface
pub type ContentIndexEvent

///|
pub extern "js" fn ContentIndexEvent::to_js_value(
  self : ContentIndexEvent,
) -> JsValue =
  #| (self) => self

///|
/// Cast JsValue to ContentIndexEvent (unchecked)
pub extern "js" fn ContentIndexEvent::from_js_value(
  v : JsValue,
) -> ContentIndexEvent =
  #| (v) => v

///|
/// Safely cast JsValue to ContentIndexEvent (checked with instanceof)
pub extern "js" fn ContentIndexEvent::from_js_value_opt(
  v : JsValue,
) -> ContentIndexEvent? =
  #| (v) => (v instanceof ContentIndexEvent) ? { $tag: 1, _0: v } : { $tag: 0 }

///|
/// Safely cast JsValue to ContentIndexEvent (checked with instanceof)
pub extern "js" fn JsValue::as_content_index_event(
  self : JsValue,
) -> ContentIndexEvent? =
  #| (self) => (self instanceof ContentIndexEvent) ? { $tag: 1, _0: self } : { $tag: 0 }

///|
/// Cast JsValue to ContentIndexEvent (unchecked)
pub extern "js" fn JsValue::to_content_index_event(
  self : JsValue,
) -> ContentIndexEvent =
  #| (self) => self

///|
pub extern "js" fn ContentIndexEvent::to_extendable_event(
  self : ContentIndexEvent,
) -> ExtendableEvent =
  #| (self) => self

///|
pub extern "js" fn ContentIndexEvent::to_event(
  self : ContentIndexEvent,
) -> Event =
  #| (self) => self

///|
extern "js" fn ContentIndexEvent::new_ffi(
  type_ : String,
  init_ : JsValue,
) -> ContentIndexEvent =
  #| (type_, init_) => new ContentIndexEvent(type_, init_)

///|
pub fn ContentIndexEvent::new(
  type_ : String,
  init_ : ContentIndexEventInit,
) -> ContentIndexEvent {
  ContentIndexEvent::new_ffi(type_, init_.to_js())
}

///|
pub extern "js" fn ContentIndexEvent::get_id(
  self : ContentIndexEvent,
) -> String =
  #| (self) => self.id