class OpenWifi::ProvisioningService < OpenWifi::BaseApi
  API_ENDPOINT = get_API_url_endpoint APPLICATION['defaults']['OPEN_WIFI']['PROVISION']['HOSTNAME'], APPLICATION['defaults']['OPEN_WIFI']['PROVISION']['PORTNUMBER']
  GATEWAY_API_ENDPOINT = get_API_url_endpoint APPLICATION['defaults']['OPEN_WIFI']['GATEWAY']['HOSTNAME'], APPLICATION['defaults']['OPEN_WIFI']['GATEWAY']['PORTNUMBER']

  def initialize ln, org=nil, router_inventory=nil
    @ln = ln
    @int_type = get_integration_details @ln, org, router_inventory
    @provision_endpoint = get_controller_details @int_type, 'PROVISION'
    @gateway_endpoint = get_controller_details @int_type, 'GATEWAY'
  end

    def add_device_with_config router_inventory, swhb=false
      return update_switch_configuration router_inventory,swhb if router_inventory.switch?
      device_detail = get_device_details router_inventory.mac_id
      if device_detail.present? 
        if device_detail['ErrorCode'] == 404
          computed_config = OpenWifi::ObjectMapper.get_computed_configuration router_inventory

          force_config = router_inventory.force_config(@int_type)
          if force_config == '1' || force_config == 'true'
            apply_configuration router_inventory, computed_config, force_config
          else
            params = OpenWifi::ObjectMapper.get_device_with_config router_inventory, computed_config
            Rails.logger.info params
            query_params = {"createObjects" => {"objects" => [{"configuration" => params[:__newConfig]}]}.to_json}
            res = WrapperApi.send_request @int_type, 'POST', (@provision_endpoint + "inventory/#{mac_to_serialno router_inventory.mac_id}"), params, query_params
            Rails.logger.info "[OPENWIFI-#{router_inventory.mac_id}] Adding device with config RESPONSE::: #{res}"
            
            if res.present? && res['id'].present?
              $redis.hset("AP:#{router_inventory.mac_id}", "openwifi_config_uuid", res['deviceConfiguration'])
              apply_configuration router_inventory, computed_config, '0'
            else
              Rails.logger.info "[OPENWIFI-#{router_inventory.mac_id}] Device id is missing :: RESPONSE::: #{res}"
            end
          end
        elsif device_detail['id'].present?
          config_id = $redis.hget("AP:#{router_inventory.mac_id}", "openwifi_config_uuid")
          if config_id.blank?
            Rails.logger.info "[OPENWIFI-#{router_inventory.mac_id}] Config ID is missing!!!!"
            # create_configuration router_inventory, config_id
            computed_config = OpenWifi::ObjectMapper.get_computed_configuration router_inventory

            force_config = router_inventory.force_config(@int_type)
            if force_config == '1' || force_config == 'true'
              apply_configuration router_inventory, computed_config, force_config
            else
              config = OpenWifi::ObjectMapper.get_configuration(router_inventory, computed_config) if router_inventory.location_network.present?
              hw_type = router_inventory.hardware_part.try(:internal_name) || "cig_wf196"
              params = {
                "name" => "#{router_inventory.mac_id}",
                "deviceRules" => {
                  "rrm" => "inherit",
                  "rcOnly" => "inherit",
                  "firmwareUpgrade" => "inherit"
                },
                "deviceTypes" => [ hw_type ],
                "configuration" => config
              }
              Rails.logger.info "[OPENWIFI-#{router_inventory.mac_id}] config params Hash :: #{params}"
              res = WrapperApi.send_request @int_type, 'POST', (@provision_endpoint + "configuration/1"), params

              if res.present? && res["id"].present?
                Rails.logger.info "[OPENWIFI-#{router_inventory.mac_id}] Configuration created successfully:: #{res}"
                
                assign_config_params = {
                  "devClass" => "any",
                  "deviceConfiguration" => res["id"]
                }
                resp = WrapperApi.send_request @int_type, 'PUT', (@provision_endpoint + "inventory/#{mac_to_serialno router_inventory.mac_id}"), assign_config_params
                if resp.present? && resp["deviceConfiguration"].present?
                  $redis.hset("AP:#{router_inventory.mac_id}", "openwifi_config_uuid", res['id'])

                  Rails.logger.info "[OPENWIFI-#{router_inventory.mac_id}] Configuration assigned Successfully :: #{resp}"
                  
                  apply_configuration router_inventory, computed_config, '0'
                else
                  Rails.logger.info "[OPENWIFI-#{router_inventory.mac_id}][ERROR] Update Configuration failed :: response :: #{resp}"
                end
              else
                Rails.logger.info "[OPENWIFI-#{router_inventory.mac_id}][ERROR] Configuration not created :: #{res}"
              end
            end
          else
            update_configuration router_inventory, config_id
          end
        end
      end
    end

    def apply_configuration router_inventory, computed_config, force_config
      if force_config == '1' || force_config == 'true'
        uuid = Time.now.to_i
        #Apply config directly on gateway instead of provisioning service.
        config_params = {
          "serialNumber" => mac_to_serialno(router_inventory.mac_id),
          "when" => 0,
          "UUID" => uuid,
          "configuration" => computed_config.merge('uuid' => uuid).to_json
        }
        Rails.logger.info "[OPENWIFI-#{router_inventory.mac_id}] CONFIG-PARAMS :: #{config_params}"
        push_configuration_to_gateway config_params, router_inventory unless computed_config.blank?
      else
        res1 = WrapperApi.send_request @int_type, 'GET', (@provision_endpoint + "inventory/#{mac_to_serialno router_inventory.mac_id}"), {}, {"applyConfiguration" => true}
        Rails.logger.info "[OPENWIFI-#{router_inventory.mac_id}] Pushed config :: RESPONSE::: #{res1}"
      end
    end

    def get_device_details mac_id
      res = WrapperApi.send_request @int_type, 'GET', (@provision_endpoint + "inventory/#{mac_to_serialno mac_id}")

      res
    end

    def service_command router_inventory, command
      case command
      when "reboot"
        if router_inventory.switch?
          res = initiate_switch_reboot router_inventory
        else  
          res = WrapperApi.send_request @int_type, 'POST', (@gateway_endpoint + "device/#{mac_to_serialno router_inventory.mac_id}/reboot"), {"serialNumber" => "#{mac_to_serialno router_inventory.mac_id}","when" => 0}
        end
      when "reset"
        res = WrapperApi.send_request @int_type, 'POST', (@gateway_endpoint + "device/#{mac_to_serialno router_inventory.mac_id}/factory"), {"serialNumber" => "#{mac_to_serialno router_inventory.mac_id}","when" => 0, "keepRedirector" => false}
      when "blink"
        res = WrapperApi.send_request @int_type, 'POST', (@gateway_endpoint + "device/#{mac_to_serialno router_inventory.mac_id}/leds"), {"serialNumber" => "#{mac_to_serialno router_inventory.mac_id}","when" => 0, "duration" => 1.second, "pattern" => "abc"}
      when "trace"
        res = WrapperApi.send_request @int_type, 'POST', (@gateway_endpoint + "device/#{mac_to_serialno router_inventory.mac_id}/trace"), {"serialNumber" => "#{mac_to_serialno router_inventory.mac_id}","when" => 0, "duration" => 1.second, "numberOfPackets" => 2, "network" => "VHC", "interface" => "example"}
      when "wifiscan"
        res = WrapperApi.send_request @int_type, 'POST', (@gateway_endpoint + "device/#{mac_to_serialno router_inventory.mac_id}/wifiscan"), {"serialNumber" => "#{mac_to_serialno router_inventory.mac_id}","verbose" => true, "activeScan" => true}
      else
      end
      res
    end

    def trace mac_id
      res = WrapperApi.send_request @int_type, 'POST', (@gateway_endpoint + "device/#{mac_to_serialno mac_id}/trace"), {"serialNumber" => "#{mac_to_serialno mac_id}","when" => 0, "duration" => 20, "network" => "up"}
      res
    end

    def file mac_id, uid
      res = WrapperApi.send_request @int_type, 'GET-FILE', (@gateway_endpoint + "file/#{uid}"), {}, {"serialNumber" => "#{mac_to_serialno mac_id}"}
      res
    end

    def upgrade router_inventory, url
      res = WrapperApi.send_request @int_type, 'POST', (@gateway_endpoint + "device/#{mac_to_serialno router_inventory.mac_id}/upgrade"), {"serialNumber" => "#{mac_to_serialno router_inventory.mac_id}","when" => 0, "uri" => url}
      res
    end

    def get_device_status mac_id
      res = WrapperApi.send_request @int_type, 'GET', (@gateway_endpoint + "device/#{mac_to_serialno mac_id}/status")
      res
    end

    def get_uuid_command uuid, mac_id
      res = WrapperApi.send_request @int_type, 'GET', (@gateway_endpoint + "command/#{uuid}?serialNumber=#{mac_to_serialno(mac_id)}")
      res
    end


    def update_device_configuration mac_id, params
      #TODO: get router inventory from mac_id
      device_detail = get_device_details mac_id
      Rails.logger.info  "[OPENWIFI] DEVICE: #{device_detail}"
      if device_detail.present? 
        if device_detail['deviceConfiguration']
          res = WrapperApi.send_request @int_type, 'PUT', (@provision_endpoint + "inventory/#{mac_to_serialno mac_id}"), params

          res
        else
        end
      else 
        Rails.logger.info "device config not found for the respective device"
      end
    end

    def switch_configuration router_inventory
       computed_config, mac_vlans = OpenWifi::ObjectMapper.get_switch_port_configuration router_inventory
       return computed_config, mac_vlans
    end

    def push_configuration_to_gateway params, router_inventory
      # res1 = WrapperApi.send_request @int_type, 'GET', (@provision_endpoint + "inventory/#{mac_to_serialno router_inventory.mac_id}"), params, {"applyConfiguration" => true}
      #Save the last config consume id 
      $redis.hset "AP:#{router_inventory.mac_id}", "CONSUME_ID", params['UUID'].to_s
      $redis.set router_inventory.mac_id, {"BASIC_CONFIG" => {"CONSUME_ID" => params['UUID'].to_s},"NETWORK_ID" => "lnsocket#{router_inventory.location_network.try(:id)}", "CONFIG" => params}.to_json

      res1 = WrapperApi.send_request @int_type, 'POST', (@gateway_endpoint + "device/#{mac_to_serialno router_inventory.mac_id}/configure"), params
      Rails.logger.info "[OPENWIFI-#{router_inventory.mac_id}] CONFIG-PUSH-GATEWAY :: Pushed config to gateway :: RESPONSE :: #{res1}"

      res1
    end

    def send_mac_vlan router_inventory, mac_vlans
      mac_vlans.each do |x|
        initiate_set_macvlan router_inventory, 'setMacVlan', x["macaddress"].gsub(":","-"), x["mask"].blank? ? "ff-ff-ff-ff-ff-ff" : x["mask"].gsub(":","-"), x["vlanid"]
      end
    end

    def initiate_set_macvlan(router_inventory, cmd, *args)
      response = `/bin/eapRemoteCmd.sh #{get_Port(router_inventory)} #{cmd} #{args[0]} #{args[1]} #{args[2]}`
      Rails.logger.info "[OPENWIFI COMMAND] :: /bin/eapRemoteCmd.sh #{get_Port(router_inventory)} #{cmd} #{args[0]} #{args[1]} #{args[2]} :: #{response}"
    end

    def initiate_switch_reboot router_inventory
      response = `/bin/eapRemoteCmd.sh #{get_Port(router_inventory)} reloadDevice`
      return {"status"=>true}
    end

    def update_switch_configuration router_inventory, swhb=false
      computed_config, mac_vlans = switch_configuration router_inventory
      uuid = Time.now.to_i
      if swhb
        existing_consumerid = $redis.hget "AP:#{router_inventory.mac_id}", "CONSUME_ID"
        uuid = existing_consumerid.to_i unless existing_consumerid.blank? 
      end
      
      config_params = {
        "serialNumber" => mac_to_serialno(router_inventory.mac_id),
        "when" => 0,
        "UUID" => uuid,
        "configuration" => computed_config.merge('uuid' => uuid).to_json
      }
      Rails.logger.info "[OPENWIFI-SWITCH-#{router_inventory.mac_id}] :: Configuration to be pushed :: #{config_params}"
      push_configuration_to_gateway config_params,router_inventory unless computed_config.blank?
      # send_mac_vlan router_inventory, mac_vlans unless mac_vlans.blank?
    end

    def update_configuration router_inventory, config_id,swhb=false
      return update_switch_configuration router_inventory,swhb if router_inventory.switch?
      device_detail = get_device_details router_inventory.mac_id
      Rails.logger.info  "[OPENWIFI]- #{device_detail}"
      if device_detail.present?
        if device_detail['deviceConfiguration']
          params =[]
          computed_config = OpenWifi::ObjectMapper.get_computed_configuration router_inventory

          force_config = router_inventory.force_config(@int_type)
          if force_config == '1' || force_config == 'true'
            apply_configuration router_inventory, computed_config, force_config
          else          
            params = OpenWifi::ObjectMapper.get_configuration(router_inventory, computed_config) if router_inventory.location_network.present?
          
            config = {}
            config[:configuration] = params
            config[:id] = config_id
            config["deviceTypes"] = [router_inventory.hardware_part.try(:internal_name)] unless router_inventory.hardware_part.blank?
            Rails.logger.info config
            res = WrapperApi.send_request @int_type, 'PUT', (@provision_endpoint + "configuration/#{config_id}"), config
            Rails.logger.info "[OPENWIFI-#{router_inventory.mac_id}] Update config RESPONSE::: #{res}"
            if res['id'].present?
              apply_configuration router_inventory, computed_config, '0'
            else
              Rails.logger.info "[OPENWIFI-#{router_inventory.mac_id}][ERROR] Update Configuration failed :: response :: #{res}"            
            end
          end
        end
      end
    end

    def get_capabilities router_inventory
      band_map = {"2G" => 1, "5G" => 2, "6G" => 3}
      res = WrapperApi.send_request @int_type, 'GET', (@gateway_endpoint + "device/#{mac_to_serialno router_inventory.mac_id}/capabilities"), {}
      p res
      band = {}
      if res['capabilities'].present?
        res['capabilities']['wifi'].each do |phy, radio|
          band[phy] = band_map[(radio['band'] || []).first]
        end
      end

      $redis.hset("AP:#{router_inventory.mac_id}", "bandPhyMap", band.to_json) unless band.blank?
      band
    end

    def enable_telemetry_config router_inventory, timespan=2592000
      params = {  "serialNumber" => mac_to_serialno(router_inventory.mac_id),
                  "interval" => 30,
                  "lifetime" => timespan,
                  "kafka" => true,
                  "types" => [
                    "wifi-frames"
                  ]
                }
      res = WrapperApi.send_request @int_type, 'POST', (@gateway_endpoint + "device/#{mac_to_serialno router_inventory.mac_id}/telemetry"), params
      Rails.logger.info "[OPENWIFI-#{router_inventory.mac_id}] Pushed Telemetry config RESPONSE::: #{res}"    
    end

    def get_radius_proxy_config
      #TODO: Select the controller based on controller endpoint
      res = WrapperApi.send_request @int_type, 'GET', (GATEWAY_API_ENDPOINT + "radiusProxyConfig"), {}
      Rails.logger.info "[OPENWIFI][Get radius proxy config] Response :: #{res}"
      pools = []
      if res['pools'].present?
        Rails.logger.info "[OPENWIFI][Radius Proxy Config] :: #{pools}"
        pools = res['pools']
      end
    end

    def set_radius_proxy_config
      # existing_pools = get_radius_proxy_config
      ssids_rad_gw_proxy = NetworkSsid.includes(:location_network).where(radius_gw_proxy: true).where("location_networks.vendor_type = ?", "4").references(:location_network)
      params = {"pools" => []}
      ssids_rad_gw_proxy.each do |s|
        if ((s.security_mode == 'psk2' && s.multi_psk == 'radius') || s.captive_portal.to_i != 0)
          params['pools'] << OpenWifi::ObjectMapper.get_radius_proxy_config(s)
        end
      end
      Rails.logger.info "[OPENWIFI][Get radius proxy config] Params :: #{params}"
      #TODO: Select the controller based on controller endpoint
      res = WrapperApi.send_request @int_type, 'PUT', (GATEWAY_API_ENDPOINT + "radiusProxyConfig"), params
      Rails.logger.info "[OPENWIFI][Get radius proxy config] Response :: #{res}"
      if res['pools'].present?
        Rails.logger.info "[OPENWIFI][Radius Proxy Config] :: #{res['pools']}"
        Rails.logger.info "[OPENWIFI] Radius Proxy Config Updated successfully"
      end
    end

    def get_Port router_inventory
      6000 + router_inventory.mac_id.split(":")[5].hex
    end
end

# require "uri"
# require "net/http"


# url = URI(URI.encode('https://openwifi.wlan.local:16005/api/v1/inventory/000C661099EE?createObjects={"objects" => [{"configuration":{"rrm":"inherit","firmwareUpgrade":"no","firmwareRCOnly":false,"configuration":[{"name":"Radios","description":"","weight":1,"configuration":{"radios":[{"band":"2G","country":"US","channel-width":20,"channel":1},{"band":"5G","country":"US","channel-width":80,"channel":36}]}},{"name":"Interfaces","description":"","weight":1,"configuration":{"interfaces":[{"name":"WAN","role":"upstream","services":["ssh","lldp","dhcp-snooping"],"ethernet":[{"select-ports":["WAN*"]}],"ipv4":{"addressing":"dynamic"},"ssids":[{"name":"ssid_wpa_eap_2g","bss-mode":"ap","wifi-bands":["2G"],"services":["wifi-frames"],"encryption":{"proto":"wpa","ieee80211w":"optional"},"radius":{"authentication":{"host":"10.10.1.221","port":1812,"secret":"testing123"},"accounting":{"host":"10.10.1.221","port":1813,"secret":"testing123"}}},{"name":"ssid_wpa_eap_5g","bss-mode":"ap","wifi-bands":["5G"],"services":["wifi-frames"],"encryption":{"proto":"wpa","ieee80211w":"optional"},"radius":{"authentication":{"host":"10.10.1.221","port":1812,"secret":"testing123"},"accounting":{"host":"10.10.1.221","port":1813,"secret":"testing123"}}}]},{"name":"LAN","role":"downstream","services":["ssh","lldp","dhcp-snooping"],"ethernet":[{"select-ports":["LAN*"]}],"ipv4":{"addressing":"static","subnet":"192.168.1.1/16","dhcp":{"lease-first":10,"lease-count":10000,"lease-time":"6h"}}}]}},{"name":"Metrics","description":"","weight":1,"configuration":{"metrics":{"statistics":{"interval":60,"types":["ssids","lldp","clients"]},"health":{"interval":120},"wifi-frames":{"filters":["probe","auth","assoc","disassoc","deauth","local-deauth","inactive-deauth","key-mismatch","beacon-report","radar-detected"]},"dhcp-snooping":{"filters":["ack","discover","offer","request","solicit","reply","renew"]}}}},{"name":"Services","description":"","weight":1,"configuration":{"services":{"lldp":{"describe":"TIP OpenWiFi","location":"QA"},"ssh":{"port":22}}}}],"name":"device:000C661099EE","description":"Created from the Edit Tag menu","deviceTypes":["cig_wf194c"]}}]}'))
# # url = URI('https://openwifi.wlan.local:16005/api/v1/inventory/000C661099EE?createObjects={"objects":[{"configuration":{"rrm":"inherit","firmwareUpgrade":"no","firmwareRCOnly":false,"configuration":[{"name":"Radios","description":"","weight":1,"configuration":{"radios":[{"band":"2G","country":"US","channel-width":20,"channel":1},{"band":"5G","country":"US","channel-width":80,"channel":36}]}},{"name":"Interfaces","description":"","weight":1,"configuration":{"interfaces":[{"name":"WAN","role":"upstream","services":["ssh","lldp","dhcp-snooping"],"ethernet":[{"select-ports":["WAN*"]}],"ipv4":{"addressing":"dynamic"},"ssids":[{"name":"ssid_wpa_eap_2g","bss-mode":"ap","wifi-bands":["2G"],"services":["wifi-frames"],"encryption":{"proto":"wpa","ieee80211w":"optional"},"radius":{"authentication":{"host":"10.10.1.221","port":1812,"secret":"testing123"},"accounting":{"host":"10.10.1.221","port":1813,"secret":"testing123"}}},{"name":"ssid_wpa_eap_5g","bss-mode":"ap","wifi-bands":["5G"],"services":["wifi-frames"],"encryption":{"proto":"wpa","ieee80211w":"optional"},"radius":{"authentication":{"host":"10.10.1.221","port":1812,"secret":"testing123"},"accounting":{"host":"10.10.1.221","port":1813,"secret":"testing123"}}}]},{"name":"LAN","role":"downstream","services":["ssh","lldp","dhcp-snooping"],"ethernet":[{"select-ports":["LAN*"]}],"ipv4":{"addressing":"static","subnet":"192.168.1.1/16","dhcp":{"lease-first":10,"lease-count":10000,"lease-time":"6h"}}}]}},{"name":"Metrics","description":"","weight":1,"configuration":{"metrics":{"statistics":{"interval":60,"types":["ssids","lldp","clients"]},"health":{"interval":120},"wifi-frames":{"filters":["probe","auth","assoc","disassoc","deauth","local-deauth","inactive-deauth","key-mismatch","beacon-report","radar-detected"]},"dhcp-snooping":{"filters":["ack","discover","offer","request","solicit","reply","renew"]}}}},{"name":"Services","description":"","weight":1,"configuration":{"services":{"lldp":{"describe":"TIP OpenWiFi","location":"QA"},"ssh":{"port":22}}}}],"name":"device:000C661099EE","description":"Created from the Edit Tag menu","deviceTypes":["cig_wf194c"]}}]}')

# https = Net::HTTP.new(url.host, url.port)
# https.use_ssl = true
# https.verify_mode = OpenSSL::SSL::VERIFY_NONE 
# # request = Net::HTTP::Get.new(url)
# request = Net::HTTP::Post.new(url)
# request["Authorization"] = "Bearer 9091417fc5ce67f739641bf03cb55362dfa5e03c64a435f746e2c6d30b1ee16b"
# request["Content-Type"] = "application/json"
# request.body = {:name=>"RaviPC14", :description=>"", :serialNumber=>"000C661099EE", :rrm=>"inherit", :deviceType=>"cig_wf194c", :devClass=>"any", :__newConfig=>{:rrm=>"inherit", :firmwareUpgrade=>"no", :firmwareRCOnly=>false, :configuration=>[{"name"=>"Metrics", "description"=>"", "weight"=>1, "configuration"=>{"metrics"=>{"configuration"=>{"dhcp-snooping"=>{"filters"=>["ack", "discover", "offer", "request", "solicit", "reply", "renew"]}, "wifi-frames"=>{"filters"=>["probe", "auth", "assoc", "disassoc", "deauth", "local-deauth", "inactive-deauth", "key-mismatch", "beacon-report", "radar-detected"]}, "health"=>{"interval"=>60}, "statistics"=>{"types"=>["ssids", "lldp", "clients"], "interval"=>60}}, "description"=>"", "name"=>"Metrics", "weight"=>1}}}, {"name"=>"Interfaces", "description"=>"", "weight"=>1, "configuration"=>{"interfaces"=>[{"name"=>"WAN", "role"=>"upstream", "services"=>[], "ethernet"=>[{"select-ports"=>["WAN*"]}], "ipv4"=>{"addressing"=>"dynamic"}, "ssids"=>[{"name"=>"pc14", "hidden-ssid"=>false, "bss-mode"=>"ap", "wifi-bands"=>["2G"], "maximum-clients"=>3, "isolate-clients"=>false, "services"=>["wifi-frames"], "encryption"=>{"proto"=>"psk2", "ieee80211w"=>"optional", "key"=>"12121212"}}, {"name"=>"new_virama", "hidden-ssid"=>false, "bss-mode"=>"ap", "wifi-bands"=>["2G"], "maximum-clients"=>0, "isolate-clients"=>false, "services"=>["wifi-frames"], "encryption"=>{"proto"=>"psk2", "ieee80211w"=>"optional", "key"=>"12121212"}}, {"name"=>"RaviTest", "hidden-ssid"=>false, "bss-mode"=>"ap", "wifi-bands"=>["2G", "5G"], "maximum-clients"=>10, "isolate-clients"=>false, "services"=>["wifi-frames"], "encryption"=>{"proto"=>"psk2", "ieee80211w"=>"optional", "key"=>"Wavesp0t"}}]}, {"name"=>"LAN", "role"=>"downstream", "services"=>["ssh", "lldp", "dhcp-snooping"], "ethernet"=>[{"select-ports"=>["LAN*"]}], "ipv4"=>{"addressing"=>"dynamic"}}]}}], :name=>"device:000C661099EE", :description=>"Created from Pronto", :deviceTypes=>["edgecore_eap101"]}}.to_json
# # request.body = {:name=>"RaviPC14", :description=>"", :serialNumber=>"000C661099EE", :rrm=>"inherit", :deviceType=>"cig_wf194c", :devClass=>"any", :__newConfig=>{:rrm=>"inherit", :firmwareUpgrade=>"no", :firmwareRCOnly=>false, :configuration=>[{"name"=>"Interfaces", "description"=>"", "weight"=>1, "configuration"=>{"metrics"=>{"configuration"=>{"wifi-frames"=>{"filters"=>["probe", "auth", "assoc", "disassoc", "deauth", "local-deauth", "inactive-deauth", "key-mismatch", "beacon-report", "radar-detected"]}, "health"=>{"interval"=>60}, "statistics"=>{"types"=>["ssids", "lldp", "clients"], "interval"=>60}}, "description"=>"", "name"=>"Metrics", "weight"=>1}, "interfaces"=>[{"name"=>"WAN", "role"=>"upstream", "services"=>[], "ethernet"=>[{"select-ports"=>["WAN*"]}], "ipv4"=>{"addressing"=>"dynamic"}, "ssids"=>[{"name"=>"pc14", "hidden-ssid"=>false, "bss-mode"=>"ap", "wifi-bands"=>["2G"], "maximum-clients"=>3, "isolate-clients"=>false, "services"=>["wifi-frames"], "encryption"=>{"proto"=>"psk2", "ieee80211w"=>"optional", "key"=>"12121212"}}, {"name"=>"new_virama", "hidden-ssid"=>false, "bss-mode"=>"ap", "wifi-bands"=>["2G"], "maximum-clients"=>0, "isolate-clients"=>false, "services"=>["wifi-frames"], "encryption"=>{"proto"=>"psk2", "ieee80211w"=>"optional", "key"=>"12121212"}}, {"name"=>"RaviTest", "hidden-ssid"=>false, "bss-mode"=>"ap", "wifi-bands"=>["2G", "5G"], "maximum-clients"=>10, "isolate-clients"=>false, "services"=>["wifi-frames"], "encryption"=>{"proto"=>"psk2", "ieee80211w"=>"optional", "key"=>"Wavesp0t"}}]}, {"name"=>"LAN", "role"=>"downstream", "services"=>["ssh", "lldp", "dhcp-snooping"], "ethernet"=>[{"select-ports"=>["LAN*"]}], "ipv4"=>{"addressing"=>"dynamic"}}]}}], :name=>"device:000C661099EE", :description=>"Created from Pronto", :deviceTypes=>["edgecore_eap101"]}}.to_json

# response = https.request(request)
# puts response.read_body
