{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://calvagone.github.io/campsis.doc/schema/1.0/campsis_settings.schema.json",
  "$comment": "Campsis Settings JSON Schema v1.0 © 2025 [Nicolas Luyckx / Calvagone]. Licensed under CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). You are free to share and adapt this schema with attribution.",
  "title": "Campsis Settings JSON Schema",
  "$ref": "#/$defs/settings",
  "$defs": {
    "settings": {
      "type": "array",
      "items": {
        "oneOf": [
          {
            "$ref": "#/$defs/default_settings"
          },
          {
            "$ref": "#/$defs/hardware_settings"
          }
        ]
      }
    },
    "default_settings": {
      "type": "object",
      "properties": {
        "type": {
          "const": "default_settings",
          "default": "default_settings"
        },
        "engine": {
          "enum": [
            "mrgsolve",
            "rxode2"
          ]
        },
        "seed": {
          "type": "integer"
        },
        "replicates": {
          "type": "integer",
          "minimum": 1,
          "description": "Number of replicates. Optional, defaults to 1."
        },
        "outvars": {
          "type": "array",
          "items": {
            "type": "string"
          }
        },
        "outfuns": {
          "type": "array",
          "items": {
            "oneOf": [
              {
                "$ref": "#/$defs/pi_outfun"
              },
              {
                "$ref": "#/$defs/stats_outfun"
              },
              {
                "$ref": "#/$defs/nca_table_outfun"
              },
              {
                "$ref": "#/$defs/default_outfun"
              }
            ],
            "discriminator": {
              "propertyName": "type"
            }
          }
        },
        "disabled_variabilities": {
          "type": "array",
          "items": {
            "enum": [
              "IIV",
              "RUV"
            ]
          }
        }
      },
      "required": [
        "type",
        "engine",
        "seed"
      ],
      "additionalProperties": false
    },
    "hardware_settings": {
      "type": "object",
      "properties": {
        "type": {
          "const": "hardware_settings",
          "default": "hardware_settings"
        },
        "cpu": {
          "type": "integer",
          "minimum": 1,
          "description": "Number of CPU cores."
        },
        "replicate_parallel": {
          "type": "boolean",
          "description": "Should replicates be simulated in parallel?"
        }
      },
      "required": [
        "cpu",
        "replicate_parallel"
      ],
      "additionalProperties": false
    },
    "pi_outfun": {
      "type": "object",
      "properties": {
        "type": {
          "const": "pi_outfun",
          "default": "pi_outfun"
        },
        "name": {
          "type": "string",
          "description": "Name of the output function (used for labeling the Campsis output). This name is optional. If not provided, the default name will be 'pi_<variable>_<pi_level>'"
        },
        "variable": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Variable(s) for which the prediction interval is computed"
        },
        "strata": {
          "$ref": "#/$defs/outfun_strata",
          "description": "Named strata filters used to subset the Campsis output. See outfun_strata definition."
        },
        "pi_level": {
          "type": "number",
          "description": "Prediction interval level (between 0 and 1)"
        }
      },
      "required": [
        "type",
        "variable",
        "pi_level"
      ],
      "additionalProperties": false
    },
    "stats_outfun": {
      "type": "object",
      "properties": {
        "type": {
          "const": "stats_outfun",
          "default": "stats_outfun"
        },
        "name": {
          "type": "string",
          "description": "Name of the output function (used for labeling the Campsis output). This name is optional. If not provided, the default name will be 'stats_<variable>'"
        },
        "variable": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "Variable(s) for which the statistics are computed"
        },
        "strata": {
          "$ref": "#/$defs/outfun_strata",
          "description": "Named strata filters used to subset the Campsis output. See outfun_strata definition."
        },
        "stats": {
          "type": "array",
          "items": {
            "type": "string"
          },
          "description": "statistics to compute. Supported: 'median', 'mean', or percentiles like 'p5', 'p95'."
        }
      },
      "required": [
        "type",
        "variable",
        "stats"
      ],
      "additionalProperties": false
    },
    "outfun_strata": {
      "type": "object",
      "description": "Named strata filters used to subset the dataset (e.g., ARM, SCENARIO). Each property name represents a column and its value the level to select. Use value 'all' to select all levels of a column. Example: {\"ARM\": \"Arm 1\", \"SCENARIO\": \"all\"} selects all rows where ARM is Arm 1, regardless of SCENARIO.",
      "additionalProperties": {
        "type": "string"
      },
      "minProperties": 1
    },
    "default_outfun": {
      "type": "object",
      "properties": {
        "type": {
          "const": "default_outfun",
          "default": "default_outfun"
        }
      },
      "required": [
        "type"
      ],
      "additionalProperties": false
    },
    "nca_table_outfun": {
      "type": "object",
      "properties": {
        "type": {
          "const": "nca_table_outfun",
          "default": "nca_table_outfun"
        },
        "name": {
          "type": "string",
          "description": "Name of the output function (used for labeling the Campsis output). This name is optional."
        },
        "table": {
          "type": "string",
          "description": "NCA table (see campsisnca package) in JSON format"
        },
        "export_type": {
          "enum": [
            "summary",
            "summary_wide",
            "summary_pretty",
            "individual",
            "individual_wide"
          ]
        }
      },
      "required": [
        "type",
        "table",
        "export_type"
      ],
      "additionalProperties": false
    }
  }
}
