///
/// Locator.swift
/// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
/// https://github.com/mrousavy/nitro
/// Copyright © Marc Rousavy @ Margelo
///

import NitroModules

/**
 * Represents an instance of `Locator`, backed by a C++ struct.
 */
public typealias Locator = margelo.nitro.readium.Locator

public extension Locator {
  private typealias bridge = margelo.nitro.readium.bridge.swift

  /**
   * Create a new instance of `Locator`.
   */
  init(href: String, type: String, target: Double?, title: String?, locations: LocatorLocations?, text: LocatorText?) {
    self.init(std.string(href), std.string(type), { () -> bridge.std__optional_double_ in
      if let __unwrappedValue = target {
        return bridge.create_std__optional_double_(__unwrappedValue)
      } else {
        return .init()
      }
    }(), { () -> bridge.std__optional_std__string_ in
      if let __unwrappedValue = title {
        return bridge.create_std__optional_std__string_(std.string(__unwrappedValue))
      } else {
        return .init()
      }
    }(), { () -> bridge.std__optional_LocatorLocations_ in
      if let __unwrappedValue = locations {
        return bridge.create_std__optional_LocatorLocations_(__unwrappedValue)
      } else {
        return .init()
      }
    }(), { () -> bridge.std__optional_LocatorText_ in
      if let __unwrappedValue = text {
        return bridge.create_std__optional_LocatorText_(__unwrappedValue)
      } else {
        return .init()
      }
    }())
  }

  @inline(__always)
  var href: String {
    return String(self.__href)
  }
  
  @inline(__always)
  var type: String {
    return String(self.__type)
  }
  
  @inline(__always)
  var target: Double? {
    return { () -> Double? in
      if bridge.has_value_std__optional_double_(self.__target) {
        let __unwrapped = bridge.get_std__optional_double_(self.__target)
        return __unwrapped
      } else {
        return nil
      }
    }()
  }
  
  @inline(__always)
  var title: String? {
    return { () -> String? in
      if bridge.has_value_std__optional_std__string_(self.__title) {
        let __unwrapped = bridge.get_std__optional_std__string_(self.__title)
        return String(__unwrapped)
      } else {
        return nil
      }
    }()
  }
  
  @inline(__always)
  var locations: LocatorLocations? {
    return self.__locations.value
  }
  
  @inline(__always)
  var text: LocatorText? {
    return self.__text.value
  }
}
