///
/// GATTCharacteristic.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 `GATTCharacteristic`, backed by a C++ struct.
 */
public typealias GATTCharacteristic = margelo.nitro.munimbluetooth.GATTCharacteristic

public extension GATTCharacteristic {
  private typealias bridge = margelo.nitro.munimbluetooth.bridge.swift

  /**
   * Create a new instance of `GATTCharacteristic`.
   */
  init(uuid: String, properties: [String], value: String?, descriptors: [GATTDescriptor]?) {
    self.init(std.string(uuid), { () -> bridge.std__vector_std__string_ in
      var __vector = bridge.create_std__vector_std__string_(properties.count)
      for __item in properties {
        __vector.push_back(std.string(__item))
      }
      return __vector
    }(), { () -> bridge.std__optional_std__string_ in
      if let __unwrappedValue = value {
        return bridge.create_std__optional_std__string_(std.string(__unwrappedValue))
      } else {
        return .init()
      }
    }(), { () -> bridge.std__optional_std__vector_GATTDescriptor__ in
      if let __unwrappedValue = descriptors {
        return bridge.create_std__optional_std__vector_GATTDescriptor__({ () -> bridge.std__vector_GATTDescriptor_ in
          var __vector = bridge.create_std__vector_GATTDescriptor_(__unwrappedValue.count)
          for __item in __unwrappedValue {
            __vector.push_back(__item)
          }
          return __vector
        }())
      } else {
        return .init()
      }
    }())
  }

  @inline(__always)
  var uuid: String {
    return String(self.__uuid)
  }
  
  @inline(__always)
  var properties: [String] {
    return self.__properties.map({ __item in String(__item) })
  }
  
  @inline(__always)
  var value: String? {
    return { () -> String? in
      if bridge.has_value_std__optional_std__string_(self.__value) {
        let __unwrapped = bridge.get_std__optional_std__string_(self.__value)
        return String(__unwrapped)
      } else {
        return nil
      }
    }()
  }
  
  @inline(__always)
  var descriptors: [GATTDescriptor]? {
    return { () -> [GATTDescriptor]? in
      if bridge.has_value_std__optional_std__vector_GATTDescriptor__(self.__descriptors) {
        let __unwrapped = bridge.get_std__optional_std__vector_GATTDescriptor__(self.__descriptors)
        return __unwrapped.map({ __item in __item })
      } else {
        return nil
      }
    }()
  }
}
