local tables = {}
local schema = os.getenv("PGSCHEMA") or "public"
local imported = 0
local skipped = 0

tables.admin = osm2pgsql.define_way_table('administratives_ardok', {
  { column = 'name', type = 'text' },
  { column = 'admin_level', type = 'text' },
  { column = 'boundary', type = 'text' },
  { column = 'geom', type = 'geometry' }
}, {
  schema = schema,
  proj = 3301
})

function osm2pgsql.process_way(object)
  local boundary = object.tags.boundary
  local admin_level = object.tags.admin_level
  if boundary == 'administrative' and admin_level then
    local geom = object:as_polygon()
    if geom then
      tables.admin:insert({
        name = object.tags.name,
        admin_level = admin_level,
        boundary = boundary,
        geom = geom
      })
      imported = imported + 1
    else
      skipped = skipped + 1
    end
  end
end

function osm2pgsql.process_end()
  print("Imporditud halduspiirkondi (ways): " .. imported)
  print("Vahele jäetud (puuduv geomeetria): " .. skipped)
end
