{
    "$schema": "http://json-schema.org/draft-04/schema",
    "title": "Resource Mapping",
    "description": "The mapping for the metrics from a SuPReMM resource to the unified format.",
    "type": "object",
    "properties": {
        "id": {
            "type": "number"
        },
        "long_name": {
            "type": "string"
        },
        "name": {
            "type": "string"
        },
        "nodes": {
            "type": "number"
        },
        "ppn": {
            "type": "number"
        },
        "start_date": {
            "type": "string"
        },
        "devices": {
            "type": "object",
            "patternProperties": {
                "netdir_(projects|work|scratch|share)": {
                    "$ref": "#/definitions/netdir"
                },
                "netdrv_([a-z]+)": {
                    "$ref": "#/definitions/netdrv"
                },
                "net_[a-z]+[0-9]+": {
                    "$ref": "#/definitions/net"
                }
            }
        },
        "attributes": {
            "type": "object",
            "patternProperties": {
                "[a-z0-9_]*": {
                    "$ref": "#/definitions/attribute"
                }
            },
            "required": [
                "local_job_id",
                "resource_name",
                "resource_id",
                "organization_id",
                "account",
                "username",
                "cwd",
                "executable",
                "exit_status",
                "granted_pe",
                "queue",
                "requested_nodes",
                "hosts",
                "nodes",
                "shared",
                "cores",
                "cores_avail",
                "submit_time_ts",
                "eligible_time_ts",
                "start_time_ts",
                "end_time_ts",
                "wall_time",
                "requested_wall_time",
                "wait_time",
                "cpu_time",
                "cpu_idle",
                "cpu_system",
                "cpu_user",
                "error",
                "flops",
                "flops_cov",
                "cpiref",
                "catastrophe",
                "cpldref",
                "cpiref_cov",
                "mem_transferred",
                "mem_transferred_cov",
                "cpu_user_imbalance",
                "cpu_user_cv",
                "memory_used",
                "memory_used_cov",
                "mem_used_including_os_caches",
                "mem_used_including_os_caches_cov",
                "ib_rx_bytes"
            ],
            "additionalProperties": false
        }
    },
    "definitions": {
        "netdir": {
            "type": "object",
            "properties": {
                "name": {
                    "type": "string"
                },
                "type": {
                    "enum": [
                        "work",
                        "home",
                        "scratch",
                        "share",
                        "projects"
                    ]
                }
            },
            "required": [
                "name",
                "type"
            ],
            "additionalProperties": false
        },
        "netdrv": {
            "type": "object",
            "properties": {
                "name": {
                    "type": "string"
                }
            },
            "required": [
                "name"
            ],
            "additionalProperties": false
        },
        "net": {
            "type": "object",
            "properties": {
                "name": {
                    "type": "string"
                }
            },
            "required": [
                "name"
            ],
            "additionalProperties": false
        },
        "attribute": {
            "type": "object",
            "oneOf": [
                {
                    "$ref": "#/definitions/refattr"
                },
                {
                    "$ref": "#/definitions/formattr"
                },
                {
                    "$ref": "#/definitions/valattr"
                },
                {
                    "$ref": "#/definitions/errattr"
                }
            ]
        },
        "refattr": {
            "type": "object",
            "properties": {
                "ref": {
                    "type": [
                        "string",
                        "array"
                    ]
                },
                "required": {
                    "type": "boolean"
                }
            },
            "required": [
                "ref"
            ],
            "additionalProperties": false
        },
        "formattr": {
            "type": "object",
            "properties": {
                "formula": {},
                "required": {
                    "type": "boolean"
                }
            },
            "required": [
                "formula"
            ],
            "additionalProperties": false
        },
        "valattr": {
            "type": "object",
            "properties": {
                "value": {},
                "required": {
                    "type": "boolean"
                }
            },
            "required": [
                "value"
            ],
            "additionalProperties": false
        },
        "errattr": {
            "type": "object",
            "properties": {
                "error": {
                    "type": "integer"
                },
                "required": {
                    "type": "boolean"
                }
            },
            "required": [
                "error"
            ],
            "additionalProperties": false
        }
    },
    "required": [
        "id",
        "long_name",
        "name",
        "nodes",
        "ppn",
        "start_date",
        "devices",
        "attributes"
    ],
    "not": {
        "anyOf": [
            {
                "required": [
                    "ref"
                ]
            },
            {
                "required": [
                    "metricErrors"
                ]
            }
        ]
    }
}