require "json"

package = JSON.parse(File.read(File.join(__dir__, "package.json")))
JECNA_API_VERSION = package["jecnaApiVersion"]

Pod::Spec.new do |s|
  s.name         = "Jecnaapi"
  s.version      = package["version"]
  s.summary      = package["description"]
  s.homepage     = package["homepage"]
  s.license      = package["license"]
  s.authors      = package["author"]

  s.platforms    = { :ios => min_ios_version_supported }
  s.source       = { :git => "https://gitea.jzitnik.dev/jzitnik/react-native-jecnaapi.git", :tag => "#{s.version}" }

  s.source_files = [
    "ios/**/*.{swift}",
    "ios/**/*.{m,mm}",
    "cpp/**/*.{hpp,cpp}",
  ]

  s.prepare_command = <<-CMD
    curl -sL "https://github.com/tomhula/JecnaAPI/releases/download/v#{JECNA_API_VERSION}/JecnaapiIOS-v#{JECNA_API_VERSION}-xcframework.zip" -o JecnaAPI.xcframework.zip
    unzip -o JecnaAPI.xcframework.zip
    rm JecnaAPI.xcframework.zip
  CMD
  s.vendored_frameworks = "JecnaAPI.xcframework"
  s.preserve_paths = "JecnaAPI.xcframework"

  s.dependency 'React-jsi'
  s.dependency 'React-callinvoker'

  load 'nitrogen/generated/ios/Jecnaapi+autolinking.rb'
  add_nitrogen_files(s)

  install_modules_dependencies(s)
end
