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

import NitroModules

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

public extension NativeDrmParams {
  private typealias bridge = margelo.nitro.video.bridge.swift

  /**
   * Create a new instance of `NativeDrmParams`.
   */
  init(type: String?, licenseUrl: String?, certificateUrl: String?, contentId: String?, licenseHeaders: Dictionary<String, String>?, multiSession: Bool?, getLicense: ((_ payload: OnGetLicensePayload) -> Promise<Promise<String>>)?) {
    self.init({ () -> bridge.std__optional_std__string_ in
      if let __unwrappedValue = type {
        return bridge.create_std__optional_std__string_(std.string(__unwrappedValue))
      } else {
        return .init()
      }
    }(), { () -> bridge.std__optional_std__string_ in
      if let __unwrappedValue = licenseUrl {
        return bridge.create_std__optional_std__string_(std.string(__unwrappedValue))
      } else {
        return .init()
      }
    }(), { () -> bridge.std__optional_std__string_ in
      if let __unwrappedValue = certificateUrl {
        return bridge.create_std__optional_std__string_(std.string(__unwrappedValue))
      } else {
        return .init()
      }
    }(), { () -> bridge.std__optional_std__string_ in
      if let __unwrappedValue = contentId {
        return bridge.create_std__optional_std__string_(std.string(__unwrappedValue))
      } else {
        return .init()
      }
    }(), { () -> bridge.std__optional_std__unordered_map_std__string__std__string__ in
      if let __unwrappedValue = licenseHeaders {
        return bridge.create_std__optional_std__unordered_map_std__string__std__string__({ () -> bridge.std__unordered_map_std__string__std__string_ in
          var __map = bridge.create_std__unordered_map_std__string__std__string_(__unwrappedValue.count)
          for (__k, __v) in __unwrappedValue {
            bridge.emplace_std__unordered_map_std__string__std__string_(&__map, std.string(__k), std.string(__v))
          }
          return __map
        }())
      } else {
        return .init()
      }
    }(), { () -> bridge.std__optional_bool_ in
      if let __unwrappedValue = multiSession {
        return bridge.create_std__optional_bool_(__unwrappedValue)
      } else {
        return .init()
      }
    }(), { () -> bridge.std__optional_std__function_std__shared_ptr_Promise_std__shared_ptr_Promise_std__string_____const_OnGetLicensePayload_____payload______ in
      if let __unwrappedValue = getLicense {
        return bridge.create_std__optional_std__function_std__shared_ptr_Promise_std__shared_ptr_Promise_std__string_____const_OnGetLicensePayload_____payload______({ () -> bridge.Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__string_____OnGetLicensePayload in
          let __closureWrapper = Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__string_____OnGetLicensePayload(__unwrappedValue)
          return bridge.create_Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__string_____OnGetLicensePayload(__closureWrapper.toUnsafe())
        }())
      } else {
        return .init()
      }
    }())
  }

  var type: String? {
    @inline(__always)
    get {
      return { () -> String? in
        if let __unwrapped = self.__type.value {
          return String(__unwrapped)
        } else {
          return nil
        }
      }()
    }
    @inline(__always)
    set {
      self.__type = { () -> bridge.std__optional_std__string_ in
        if let __unwrappedValue = newValue {
          return bridge.create_std__optional_std__string_(std.string(__unwrappedValue))
        } else {
          return .init()
        }
      }()
    }
  }
  
  var licenseUrl: String? {
    @inline(__always)
    get {
      return { () -> String? in
        if let __unwrapped = self.__licenseUrl.value {
          return String(__unwrapped)
        } else {
          return nil
        }
      }()
    }
    @inline(__always)
    set {
      self.__licenseUrl = { () -> bridge.std__optional_std__string_ in
        if let __unwrappedValue = newValue {
          return bridge.create_std__optional_std__string_(std.string(__unwrappedValue))
        } else {
          return .init()
        }
      }()
    }
  }
  
  var certificateUrl: String? {
    @inline(__always)
    get {
      return { () -> String? in
        if let __unwrapped = self.__certificateUrl.value {
          return String(__unwrapped)
        } else {
          return nil
        }
      }()
    }
    @inline(__always)
    set {
      self.__certificateUrl = { () -> bridge.std__optional_std__string_ in
        if let __unwrappedValue = newValue {
          return bridge.create_std__optional_std__string_(std.string(__unwrappedValue))
        } else {
          return .init()
        }
      }()
    }
  }
  
  var contentId: String? {
    @inline(__always)
    get {
      return { () -> String? in
        if let __unwrapped = self.__contentId.value {
          return String(__unwrapped)
        } else {
          return nil
        }
      }()
    }
    @inline(__always)
    set {
      self.__contentId = { () -> bridge.std__optional_std__string_ in
        if let __unwrappedValue = newValue {
          return bridge.create_std__optional_std__string_(std.string(__unwrappedValue))
        } else {
          return .init()
        }
      }()
    }
  }
  
  var licenseHeaders: Dictionary<String, String>? {
    @inline(__always)
    get {
      return { () -> Dictionary<String, String>? in
        if let __unwrapped = self.__licenseHeaders.value {
          return { () -> Dictionary<String, String> in
            var __dictionary = Dictionary<String, String>(minimumCapacity: __unwrapped.size())
            let __keys = bridge.get_std__unordered_map_std__string__std__string__keys(__unwrapped)
            for __key in __keys {
              let __value = bridge.get_std__unordered_map_std__string__std__string__value(__unwrapped, __key)
              __dictionary[String(__key)] = String(__value)
            }
            return __dictionary
          }()
        } else {
          return nil
        }
      }()
    }
    @inline(__always)
    set {
      self.__licenseHeaders = { () -> bridge.std__optional_std__unordered_map_std__string__std__string__ in
        if let __unwrappedValue = newValue {
          return bridge.create_std__optional_std__unordered_map_std__string__std__string__({ () -> bridge.std__unordered_map_std__string__std__string_ in
            var __map = bridge.create_std__unordered_map_std__string__std__string_(__unwrappedValue.count)
            for (__k, __v) in __unwrappedValue {
              bridge.emplace_std__unordered_map_std__string__std__string_(&__map, std.string(__k), std.string(__v))
            }
            return __map
          }())
        } else {
          return .init()
        }
      }()
    }
  }
  
  var multiSession: Bool? {
    @inline(__always)
    get {
      return self.__multiSession.value
    }
    @inline(__always)
    set {
      self.__multiSession = { () -> bridge.std__optional_bool_ in
        if let __unwrappedValue = newValue {
          return bridge.create_std__optional_bool_(__unwrappedValue)
        } else {
          return .init()
        }
      }()
    }
  }
  
  var getLicense: ((_ payload: OnGetLicensePayload) -> Promise<Promise<String>>)? {
    @inline(__always)
    get {
      return { () -> ((_ payload: OnGetLicensePayload) -> Promise<Promise<String>>)? in
        if let __unwrapped = self.__getLicense.value {
          return { () -> (OnGetLicensePayload) -> Promise<Promise<String>> in
            let __wrappedFunction = bridge.wrap_Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__string_____OnGetLicensePayload(__unwrapped)
            return { (__payload: OnGetLicensePayload) -> Promise<Promise<String>> in
              let __result = __wrappedFunction.call(__payload)
              return { () -> Promise<Promise<String>> in
                let __promise = Promise<Promise<String>>()
                let __resolver = { (__result: Promise<String>) in
                  __promise.resolve(withResult: __result)
                }
                let __rejecter = { (__error: Error) in
                  __promise.reject(withError: __error)
                }
                let __resolverCpp = { () -> bridge.Func_void_std__shared_ptr_Promise_std__string__ in
                  let __closureWrapper = Func_void_std__shared_ptr_Promise_std__string__(__resolver)
                  return bridge.create_Func_void_std__shared_ptr_Promise_std__string__(__closureWrapper.toUnsafe())
                }()
                let __rejecterCpp = { () -> bridge.Func_void_std__exception_ptr in
                  let __closureWrapper = Func_void_std__exception_ptr(__rejecter)
                  return bridge.create_Func_void_std__exception_ptr(__closureWrapper.toUnsafe())
                }()
                let __promiseHolder = bridge.wrap_std__shared_ptr_Promise_std__shared_ptr_Promise_std__string____(__result)
                __promiseHolder.addOnResolvedListener(__resolverCpp)
                __promiseHolder.addOnRejectedListener(__rejecterCpp)
                return __promise
              }()
            }
          }()
        } else {
          return nil
        }
      }()
    }
    @inline(__always)
    set {
      self.__getLicense = { () -> bridge.std__optional_std__function_std__shared_ptr_Promise_std__shared_ptr_Promise_std__string_____const_OnGetLicensePayload_____payload______ in
        if let __unwrappedValue = newValue {
          return bridge.create_std__optional_std__function_std__shared_ptr_Promise_std__shared_ptr_Promise_std__string_____const_OnGetLicensePayload_____payload______({ () -> bridge.Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__string_____OnGetLicensePayload in
            let __closureWrapper = Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__string_____OnGetLicensePayload(__unwrappedValue)
            return bridge.create_Func_std__shared_ptr_Promise_std__shared_ptr_Promise_std__string_____OnGetLicensePayload(__closureWrapper.toUnsafe())
          }())
        } else {
          return .init()
        }
      }()
    }
  }
}
