{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "$id": "https://vparis-ns.obspm.fr/maser/tfcat/v1.0/schema#",
    "title": "TFCat",
    "type": "object",
    "required": [
        "type",
        "features",
        "crs"
    ],
    "properties": {
        "type": {
            "type": "string",
            "enum": ["FeatureCollection"]
        },
        "features": {
            "type": "array",
            "items": {
                "title": "TFCat Feature",
                "type": "object",
                "required": [
                    "type",
                    "properties",
                    "geometry"
                ],
                "properties": {
                    "type": {
                        "type": "string",
                        "enum": ["Feature"]
                    },
                    "id": {
                        "oneOf": [
                            {"type": "number"},
                            {"type": "string"}
                        ]
                    },
                    "name": {
                        "oneOf": [
                            {"type": "null"},
                            {"type": "string"}
                        ]
                    },
                    "properties": {
                        "oneOf": [
                            {"type": "null"},
                            {"type": "object"}
                        ]
                    },
                    "geometry": {
                        "oneOf": [
                            {"type": "null"},
                            {"$ref": "#/$defs/TFCatPoint"},
                            {"$ref": "#/$defs/TFCatLineString"},
                            {"$ref": "#/$defs/TFCatPolygon"},
                            {"$ref": "#/$defs/TFCatMultiPoint"},
                            {"$ref": "#/$defs/TFCatMultiLineString"},
                            {"$ref": "#/$defs/TFCatMultiPolygon"},
                            {
                                "title": "TFCat GeometryCollection",
                                "type": "object",
                                "required": [
                                    "type",
                                    "geometries"
                                ],
                                "properties": {
                                    "type": {
                                        "type": "string",
                                        "enum": ["GeometryCollection"]
                                    },
                                    "geometries": {
                                        "type": "array",
                                        "items": {
                                            "oneOf": [
                                                {"$ref": "#/$defs/TFCatPoint"},
                                                {"$ref": "#/$defs/TFCatLineString"},
                                                {"$ref": "#/$defs/TFCatPolygon"},
                                                {"$ref": "#/$defs/TFCatMultiPoint"},
                                                {"$ref": "#/$defs/TFCatMultiLineString"},
                                                {"$ref": "#/$defs/TFCatMultiPolygon"}
                                            ]
                                        }
                                    },
                                    "bbox": {"$ref": "#/$defs/bbox"}
                                }
                            }
                        ]
                    },
                    "bbox": {"$ref": "#/$defs/bbox"}
                }
            }
        },
        "bbox": {"$ref": "#/$defs/bbox"},
        "properties": {
            "oneOf": [
                {"type": "null"},
                {"type": "object"}
            ]
        },
        "fields": {
            "oneOf": [
                {"type": "null"},
                {
                    "type": "object",
                    "patternProperties": {
                        ".*": {
                            "type": "object",
                            "required": [
                                "info",
                                "ucd",
                                "datatype"
                            ],
                            "properties": {
                                "info": {
                                    "type": "string",
                                    "$comment": "A description of the the current field"
                                },
                                "ucd": {
                                    "type": "string",
                                    "$comment": "A valid UCD (IVOA Unified Content Description)."
                                },
                                "datatype": {
                                    "type": "string",
                                    "enum": [
                                        "int",
                                        "float",
                                        "bool",
                                        "str"
                                    ]
                                },
                                "unit": {
                                    "type": "string",
                                    "$comment": "A valid unit, as defined in the VOUnit specification."
                                }
                            }
                        }
                    }
                }
            ]
        },
        "crs": {
            "oneOf": [
                {"$ref": "#/$defs/TFCatCRSLink"},
                {"$ref": "#/$defs/TFCatCRSLocal"},
                {"$ref": "#/$defs/TFCatCRSName"}
            ]
        }
    },
    "$defs": {
        "bbox": {
            "type": "array",
            "minItems": 4,
            "maxItems": 4,
            "items": {"type": "number"}
        },
        "coordinates": {
            "type": "array",
            "minItems": 2,
            "maxItems": 2,
            "items": {"type": "number"}
        },
        "TFCatPoint": {
            "title": "TFCat Point",
            "type": "object",
            "required": [
                "type",
                "coordinates"
            ],
            "properties": {
                "type": {
                    "type": "string",
                    "enum": ["Point"]
                },
                "coordinates": {"$ref": "#/$defs/coordinates"},
                "bbox": {"$ref": "#/$defs/bbox"}
            }
        },
        "TFCatLineString": {
            "title": "TFCat LineString",
            "type": "object",
            "required": [
                "type",
                "coordinates"
            ],
            "properties": {
                "type": {
                    "type": "string",
                    "enum": ["LineString"]
                },
                "coordinates": {
                    "type": "array",
                    "minItems": 2,
                    "items": {"$ref": "#/$defs/coordinates"}
                },
                "bbox": {"$ref": "#/$defs/bbox"}
            }
        },
        "TFCatPolygon": {
            "title": "TFCat Polygon",
            "type": "object",
            "required": [
                "type",
                "coordinates"
            ],
            "properties": {
                "type": {
                    "type": "string",
                    "enum": ["Polygon"]
                },
                "coordinates": {
                    "type": "array",
                    "items": {
                        "type": "array",
                        "minItems": 4,
                        "items": {"$ref": "#/$defs/coordinates"}
                    }
                },
                "bbox": {"$ref": "#/$defs/bbox"}
            }
        },
        "TFCatMultiPoint": {
            "title": "TFCat MultiPoint",
            "type": "object",
            "required": [
                "type",
                "coordinates"
            ],
            "properties": {
                "type": {
                    "type": "string",
                    "enum": ["MultiPoint"]
                },
                "coordinates": {
                    "type": "array",
                    "items": {"$ref": "#/$defs/coordinates"}
                },
                "bbox": {"$ref": "#/$defs/bbox"}
            }
        },
        "TFCatMultiLineString": {
            "title": "TFCat MultiLineString",
            "type": "object",
            "required": [
                "type",
                "coordinates"
            ],
            "properties": {
                "type": {
                    "type": "string",
                    "enum": ["MultiLineString"]
                },
                "coordinates": {
                    "type": "array",
                    "items": {
                        "type": "array",
                        "minItems": 2,
                        "items": {"$ref": "#/$defs/coordinates"}
                    }
                },
                "bbox": {"$ref": "#/$defs/bbox"}
            }
        },
        "TFCatMultiPolygon": {
            "title": "TFCat MultiPolygon",
            "type": "object",
            "required": [
                "type",
                "coordinates"
            ],
            "properties": {
                "type": {
                    "type": "string",
                    "enum": ["MultiPolygon"]
                },
                "coordinates": {
                    "type": "array",
                    "items": {
                        "type": "array",
                        "items": {
                            "type": "array",
                            "minItems": 4,
                            "items": {"$ref": "#/$defs/coordinates"}
                        }
                    }
                },
                "bbox": {"$ref": "#/$defs/bbox"}
            }
        },
        "TFCatCRSLink": {
            "title": "TFCAT Linked CRS",
            "type": "object",
            "required": [
                "type",
                "properties"
            ],
            "properties": {
                "type": {
                    "type": "string",
                    "enum": ["link"]
                },
                "properties": {
                    "type": "object",
                    "required": ["href"],
                    "properties": {
                        "href": {"type": "string"},
                        "type": {"type": "string"}
                    }
                }
            }
        },
        "TFCatCRSLocal": {
            "title": "TFCAT Local CRS",
            "type": "object",
            "required": [
                "type",
                "properties"
            ],
            "properties": {
                "type": {
                    "type": "string",
                    "enum": ["local"]
                },
                "properties": {
                    "type": "object",
                    "oneOf": [
                        {
                            "required": [
                                "time_coords_id",
                                "spectral_coords",
                                "ref_position_id"
                            ]
                        },
                        {
                            "required": [
                                "time_coords",
                                "spectral_coords",
                                "ref_position_id"
                            ]
                        }
                    ],
                    "properties": {
                        "time_coords": {
                            "type": "object",
                            "required": [
                                "unit",
                                "time_origin",
                                "time_scale"
                            ],
                            "properties": {
                                "name": {"type": "string"},
                                "unit": {
                                    "type": "string",
                                    "$comment": "value set to the unit of the time axis. The unit MUST be a valid VOUnit string."
                                },
                                "time_origin": {
                                    "type": "string",
                                    "$comment": "value set to the origin of the time axis, expressed in ISO 8601 format."
                                },
                                "time_scale": {
                                    "type": "string",
                                    "enum": [
                                        "GPS",
                                        "TAI",
                                        "TCB",
                                        "TCG",
                                        "TDB",
                                        "TT",
                                        "UT",
                                        "UTC",
                                        "UNKNOWN",
                                        "SCET",
                                        "SCLK"
                                    ],
                                    "$comment": "values in the list: GPS, TAI, TCB, TCG, TDB, TT, UT, UTC, UNKNOWN. The definition of the time scale terms is available from https://www.ivoa.net/rdf/timescale/ Two additional allowed values are: SCET (SpaceCraft Event Time), SCLK (Spacecraft Clock). They refer to the time measured by the spacecraft clock, SCET being transformed into a user readable unit, and SCLK is in the internal spacecraft clock format."
                                }
                            }
                        },
                        "time_coords_id": {
                            "type": "string",
                            "enum": [
                                "unix",
                                "jd",
                                "mjd",
                                "mjd_cnes",
                                "mjd_nasa",
                                "cdf_tt2000"
                            ]
                        },
                        "spectral_coords": {
                            "type": "object",
                            "required": [
                                "type",
                                "unit"
                            ],
                            "properties": {
                                "type": {
                                    "type": "string",
                                    "enum": [
                                        "frequency",
                                        "energy",
                                        "wavenumber",
                                        "wavelength"
                                    ]
                                },
                                "unit": {
                                    "type": "string",
                                    "$comment": "value set to the unit of the time axis. The unit MUST be a valid VOUnit string."
                                },
                                "scale": {
                                    "type": "string",
                                    "enum": [
                                        "linear",
                                        "log"
                                    ]
                                }
                            }
                        },
                        "ref_position_id": {
                            "type": "string",
                            "$comment": "The allowed values for this member SHOULD be either from the https://www.ivoa.net/rdf/refposition list of values, or the spacecraft name."
                        }
                    }
                }
            }
        },
        "TFCatCRSName": {
            "title": "TFCAT Named CRS",
            "type": "object",
            "required": [
                "type",
                "properties"
            ],
            "properties": {
                "type": {
                    "type": "string",
                    "enum": ["name"]
                },
                "properties": {
                    "type": "object",
                    "required": ["name"],
                    "properties": {
                        "name": {"type": "string"}
                    }
                }
            }
        }
    }
}
