{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "type": "array",
    "items": {
        "$ref": "#/definitions/provider"
    },
    "minItems": 1,
    "definitions": {
        "provider": {
            "type": "object",
            "if": {
                "properties": {
                    "type": {
                        "enum": [
                            "Individual",
                            "individual",
                            "INDIVIDUAL"
                        ]
                    }
                }
            },
            "then": {
                "$ref": "#/definitions/individual"
            },
            "else": {
                "if": {
                    "properties": {
                        "type": {
                            "enum": [
                                "Facility",
                                "facility",
                                "FACILITY"
                            ]
                        }
                    }
                },
                "then": {
                    "$ref": "#/definitions/facility"
                },
                "else": {
                    "$ref": "#/definitions/group"
                }
            }
        },
        "individual": {
            "type": "object",
            "properties": {
                "npi": {
                    "type": [
                        "string",
                        "null"
                    ],
                    "pattern": "^[0-9]{10}$"
                },
                "type": {
                    "type": "string",
                    "enum": [
                        "Individual",
                        "individual",
                        "INDIVIDUAL"
                    ]
                },
                "plans": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/plan"
                    },
                    "minItems": 1
                },
                "name": {
                    "$ref": "#/definitions/name"
                },
                "addresses": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/address"
                    },
                    "minItems": 1
                },
                "specialty": {
                    "type": "array",
                    "items": {
                        "type": "string"
                    },
                    "minItems": 1
                },
                "accepting": {
                    "type": "string",
                    "enum": [
                        "accepting",
                        "not accepting",
                        "accepting in some locations",
                        ""
                    ],
                    "description": "While an empty value of accepting is accepted and will translate to 'unknown', this should only be used with older data for backwards compatibility."
                },
                "languages": {
                    "type": "array",
                    "items": {
                        "type": "string"
                    }
                },
                "gender": {
                    "type": "string",
                    "enum": [
                        "Male",
                        "Female",
                        "Other",
                        "TransgenderFemale",
                        "TransgenderMale",
                        "NonBinary",
                        "NonDisclose",
                        "unknown",
                        ""
                    ],
                    "description": "While an empty value of gender is accepted and will translate to 'unknown', this should only be used with older data for backwards compatibility."
                },
                "last_updated_on": {
                    "type": "string",
                    "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$"
                },
				"taxonomy": {
					"type": "array",
					"items": {
						"type": "string",
						"pattern": "^([0-9]{3}[A-Z0-9]{2}[0-9]{4}[X]{1}|null)$"
					}
				},
				"certification": {
					"type": "array",
					"items": {
						"type": "string"
						"enum": ["yes", "no", ""]
					},
					"minItems": 1,
					"description": "While an empty value of certification is accepted and will translate to 'unknown', this should only be used with older data for backwards compatibility."
				},
				"telemedicine": {
					"type": "string",
					"enum": [
						"yes",
                        "no",
                        ""
                    ],
                    "description": "While an empty value of telemedicine is accepted and will translate to 'unknown', this should only be used with older data for backwards compatibility."
                }
            },
            "required": [
                "npi",
                "type",
                "plans",
                "name",
                "addresses",
                "accepting",
                "specialty",
                "last_updated_on",
				"taxonomy",
				"certification",
				"telemedicine"
            ]
        },
        "facility": {
            "type": "object",
            "properties": {
                "npi": {
                    "type": [
                        "string",
                        "null"
                    ],
                    "pattern": "^[0-9]{10}$"
                },
                "type": {
                    "type": "string",
                    "enum": [
                        "Facility",
                        "facility",
                        "FACILITY"
                    ]
                },
                "plans": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/plan"
                    },
                    "minItems": 1
                },
                "facility_name": {
                    "type": "string",
                    "minLength": 1
                },
                "facility_type": {
                    "type": "array",
                    "items": {
                        "type": "string"
                    },
                    "minItems": 1
                },
                "addresses": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/address"
                    },
                    "minItems": 1
                },
                "last_updated_on": {
                    "type": "string",
                    "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$"
                },
				"taxonomy": {
					"type": "array",
					"items": {
						"type": "string",
						"pattern": "^([0-9]{3}[A-Z0-9]{2}[0-9]{4}[X]{1}|null)$"
					}
				}
            },
            "required": [
                "npi",
                "type",
                "plans",
                "facility_name",
                "facility_type",
                "addresses",
                "last_updated_on",
				"taxonomy"
            ]
        },
        "group": {
            "type": "object",
            "properties": {
                "npi": {
                    "type": [
                        "string",
                        "null"
                    ],
                    "pattern": "^[0-9]{10}$"
                },
                "type": {
                    "type": "string",
                    "enum": [
                        "Group",
                        "group",
                        "GROUP"
                    ]
                },
                "plans": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/plan"
                    },
                    "minItems": 1
                },
                "group_name": {
                    "type": "string",
                    "minLength": 1
                },
                "addresses": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/address"
                    },
                    "minItems": 1
                },
                "last_updated_on": {
                    "type": "string",
                    "pattern": "^[0-9]{4}-[0-9]{2}-[0-9]{2}$"
                },
				"taxonomy": {
					"type": "array",
					"items": {
						"type": "string",
						"pattern": "^([0-9]{3}[A-Z0-9]{2}[0-9]{4}[X]{1}|null)$"
					}
				}
            },
            "required": [
                "npi",
                "type",
                "plans",
                "group_name",
                "addresses",
                "last_updated_on",
				"taxonomy"
            ]
        },
        "plan": {
            "type": "object",
            "properties": {
                "plan_id_type": {
                    "type": "string",
                    "enum": [
                        "FEHB-PLAN-ID",
			"PSHB-PLAN-ID"
                    ]
                },
                "plan_id": {
                    "type": "string",
                    "pattern": "^[A-Z0-9]{3}$"
                },
                "network_tier": {
                    "type": "string",
                    "pattern": "^[A-Z-]+$"
                },
                "years": {
                    "type": "array",
                    "items": {
                        "type": "integer"
                    }
                }
            },
            "required": [
                "plan_id_type",
                "plan_id",
                "network_tier",
                "years"
            ]
        },
        "name": {
            "type": "object",
            "properties": {
                "prefix": {
                    "type": [
                        "string",
                        "null"
                    ]
                },
                "first": {
                    "type": "string",
                    "minLength": 1
                },
                "middle": {
                    "type": "string"
                },
                "last": {
                    "type": "string",
                    "minLength": 1
                },
                "suffix": {
                    "type": [
                        "string",
                        "null"
                    ]
                }
            },
            "required": [
                "first",
                "last"
            ]
        },
        "address": {
            "type": "object",
            "properties": {
                "address": {
                    "type": "string",
                    "minLength": 1
                },
                "address_2": {
                    "type": "string"
                },
                "city": {
                    "type": "string",
                    "minLength": 1
                },
                "state": {
                    "type": "string",
                    "pattern": "^[A-Z]{2}$"
                },
                "zip": {
                    "type": "string",
                    "pattern": "^[0-9]{5}$"
                },
                "phone": {
                    "type": "string"
                }
            },
            "required": [
                "address",
                "city",
                "state",
                "zip"
            ]
        }
    }
}