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

public extension FetchNativeRequest {
  private typealias bridge = margelo.nitro.one.bridge.swift

  /**
   * Create a new instance of `FetchNativeRequest`.
   */
  init(url: String, method: String, headers: [FetchHeader], body: ArrayBuffer?, blob: FetchBlobRef?, form: [FetchFormPart]?, boundary: String?, omitCredentials: Bool) {
    self.init(std.string(url), std.string(method), { () -> bridge.std__vector_FetchHeader_ in
      var __vector = bridge.create_std__vector_FetchHeader_(headers.count)
      for __item in headers {
        __vector.push_back(__item)
      }
      return __vector
    }(), { () -> bridge.std__optional_std__shared_ptr_ArrayBuffer__ in
      if let __unwrappedValue = body {
        return bridge.create_std__optional_std__shared_ptr_ArrayBuffer__(__unwrappedValue.getArrayBuffer())
      } else {
        return .init()
      }
    }(), { () -> bridge.std__optional_FetchBlobRef_ in
      if let __unwrappedValue = blob {
        return bridge.create_std__optional_FetchBlobRef_(__unwrappedValue)
      } else {
        return .init()
      }
    }(), { () -> bridge.std__optional_std__vector_FetchFormPart__ in
      if let __unwrappedValue = form {
        return bridge.create_std__optional_std__vector_FetchFormPart__({ () -> bridge.std__vector_FetchFormPart_ in
          var __vector = bridge.create_std__vector_FetchFormPart_(__unwrappedValue.count)
          for __item in __unwrappedValue {
            __vector.push_back(__item)
          }
          return __vector
        }())
      } else {
        return .init()
      }
    }(), { () -> bridge.std__optional_std__string_ in
      if let __unwrappedValue = boundary {
        return bridge.create_std__optional_std__string_(std.string(__unwrappedValue))
      } else {
        return .init()
      }
    }(), omitCredentials)
  }

  @inline(__always)
  var url: String {
    return String(self.__url)
  }
  
  @inline(__always)
  var method: String {
    return String(self.__method)
  }
  
  @inline(__always)
  var headers: [FetchHeader] {
    return self.__headers.map({ __item in __item })
  }
  
  @inline(__always)
  var body: ArrayBuffer? {
    return { () -> ArrayBuffer? in
      if bridge.has_value_std__optional_std__shared_ptr_ArrayBuffer__(self.__body) {
        let __unwrapped = bridge.get_std__optional_std__shared_ptr_ArrayBuffer__(self.__body)
        return ArrayBuffer(__unwrapped)
      } else {
        return nil
      }
    }()
  }
  
  @inline(__always)
  var blob: FetchBlobRef? {
    return self.__blob.value
  }
  
  @inline(__always)
  var form: [FetchFormPart]? {
    return { () -> [FetchFormPart]? in
      if bridge.has_value_std__optional_std__vector_FetchFormPart__(self.__form) {
        let __unwrapped = bridge.get_std__optional_std__vector_FetchFormPart__(self.__form)
        return __unwrapped.map({ __item in __item })
      } else {
        return nil
      }
    }()
  }
  
  @inline(__always)
  var boundary: String? {
    return { () -> String? in
      if bridge.has_value_std__optional_std__string_(self.__boundary) {
        let __unwrapped = bridge.get_std__optional_std__string_(self.__boundary)
        return String(__unwrapped)
      } else {
        return nil
      }
    }()
  }
  
  @inline(__always)
  var omitCredentials: Bool {
    return self.__omitCredentials
  }
}
