{
 "$schema": "https://json-schema.org/draft/2020-12/schema",
 "$id": "https://husradarn.se/data/natbolag.schema.json",
 "title": "Husradarn: Sveriges nätbolag – port, mätare, aktivering och elnätsavgift",
 "description": "Öppet, bara läsande flöde. Ett objekt per nätbolag i bokstavsordning, med källa och kontrolldatum. Nätavgifter från Energimarknadsinspektionen (typkunder per 1 januari), kronor per år inklusive moms. Inga personuppgifter.",
 "type": "object",
 "required": ["sajt", "url", "beskrivning", "utgivare", "genererad", "kallor", "natavgift_forklaring", "typhushall", "mitten_av_alla_bolag_kr_per_ar_inkl_moms", "sortering", "antal", "natbolag"],
 "properties": {
  "$schema": {"type": "string"},
  "sajt": {"type": "string"},
  "url": {"type": "string", "pattern": "^https://"},
  "beskrivning": {"type": "string"},
  "utgivare": {"type": "string"},
  "genererad": {"type": "string", "pattern": "^\\d{4}-\\d{2}-\\d{2}$"},
  "uppdatering": {"type": "string"},
  "kallor": {
   "type": "object",
   "required": ["natavgift", "effektavgift", "port_och_aktivering"],
   "properties": {
    "natavgift": {"type": "string", "pattern": "^https://ei\\.se/"},
    "effektavgift": {"type": "string", "pattern": "^https://ei\\.se/"},
    "port_och_aktivering": {"type": "string"}
   }
  },
  "natavgift_forklaring": {"type": "string"},
  "typhushall": {
   "description": "Ei:s typhushåll: nyckel -> beskrivning (säkring och förbrukning per år)",
   "type": "object",
   "required": ["lgh16_2000", "villa16_5000", "villa20_10000", "villa20_20000", "villa25_20000"],
   "properties": {
    "lgh16_2000": {"type": "string"}, "villa16_5000": {"type": "string"}, "villa20_10000": {"type": "string"},
    "villa20_20000": {"type": "string"}, "villa25_20000": {"type": "string"}
   }
  },
  "mitten_av_alla_bolag_kr_per_ar_inkl_moms": {"$ref": "#/$defs/typpriser"},
  "sortering": {"type": "string"},
  "antal": {"type": "integer"},
  "natbolag": {
   "type": "array",
   "items": {
    "type": "object",
    "required": ["id", "namn", "url", "portar", "matare", "aktivering", "notiser", "natavgift", "kalla", "kontrollerad"],
    "properties": {
     "id": {"type": "string", "pattern": "^[a-z0-9-]+$"},
     "namn": {"type": "string"},
     "url": {"type": "string", "pattern": "^https://.+/natbolag/[a-z0-9-]+/$"},
     "portar": {"description": "Portar på bolagets elmätare enligt bolaget: P1 (RJ12) och/eller HAN (RJ45). Tom = står inte hos bolaget.", "type": "array", "items": {"type": "string", "pattern": "^(P1|HAN)$"}},
     "matare": {
      "type": "array",
      "items": {"type": "object", "required": ["modell", "port", "not"],
                "properties": {"modell": {"type": "string"}, "port": {"type": ["string", "null"]}, "not": {"type": ["string", "null"]}}}
     },
     "aktivering": {
      "type": "object",
      "required": ["kravs", "hur", "url", "kostnad"],
      "properties": {
       "kravs": {"description": "true = porten måste slås på hos nätbolaget, false = redan på, null = okänt", "type": ["boolean", "null"]},
       "hur": {"type": ["string", "null"]},
       "url": {"type": ["string", "null"]},
       "kostnad": {"type": ["string", "null"]}
      }
     },
     "notiser": {"type": "array", "items": {"type": "string"}},
     "natavgift": {
      "type": ["object", "null"],
      "required": ["ar", "giltig_fran", "effektavgift", "effektavgift_not", "kr_per_ar_inkl_moms", "omraden", "kalla"],
      "properties": {
       "ar": {"type": ["integer", "null"]},
       "giltig_fran": {"type": ["string", "null"], "pattern": "^\\d{4}-01-01$"},
       "effektavgift": {"description": "Ja/Nej enligt bolagets rapportering till Ei, null = uppgift saknas", "type": ["string", "null"]},
       "effektavgift_not": {"type": ["string", "null"]},
       "kr_per_ar_inkl_moms": {"$ref": "#/$defs/typpriser"},
       "omraden": {
        "type": "array",
        "items": {"type": "object", "required": ["namn"],
                  "properties": {"namn": {"type": ["string", "null"]}, "lgh16_2000": {"type": ["integer", "null"]}, "villa16_5000": {"type": ["integer", "null"]},
                                 "villa20_10000": {"type": ["integer", "null"]}, "villa20_20000": {"type": ["integer", "null"]}, "villa25_20000": {"type": ["integer", "null"]}}}
       },
       "kalla": {"type": "array", "items": {"type": "string", "pattern": "^https://"}}
      }
     },
     "kalla": {"type": "array", "items": {"type": "string"}},
     "kontrollerad": {"type": ["string", "null"], "pattern": "^\\d{4}-\\d{2}-\\d{2}$"}
    }
   }
  }
 },
 "$defs": {
  "typpriser": {
   "description": "Kronor per år inklusive moms, utan energiskatt och elpris. null = inget typpris hos Ei.",
   "type": "object",
   "required": ["lgh16_2000", "villa16_5000", "villa20_10000", "villa20_20000", "villa25_20000"],
   "properties": {
    "lgh16_2000": {"type": ["integer", "null"]}, "villa16_5000": {"type": ["integer", "null"]}, "villa20_10000": {"type": ["integer", "null"]},
    "villa20_20000": {"type": ["integer", "null"]}, "villa25_20000": {"type": ["integer", "null"]}
   }
  }
 }
}
