{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://reqview.com/schemas/2.22/config.json",
  "title": "ReqView Project Configuration File",

  "type": "object",
  "properties": {
    "id": {
      "description": "A unique project identifier; must be a valid filename",
      "$ref": "common.json#/definitions/fileName"
    },
    "description": {
      "description": "Project description; simple, multiline string",
      "$ref": "common.json#/definitions/nonEmptyString"
    },
    "group": { "$ref": "#/definitions/group" },
    "documents": {
      "description": "Array of document filenames",
      "type": "array",
      "minItems": 1,
      "uniqueItems": true,
      "items": {
        "description": "Array of valid filenames with .json extension",
        "type": "string",
        "pattern": "^[^<>:\"/\\\\|?*]+\\.[Jj][Ss][Oo][Nn]$"
      }
    },
    "hierarchy": { "$ref": "#/definitions/hierarchy" },
    "traceability": { "$ref": "#/definitions/traceability" },
    "linkedProjects": { "$ref": "#/definitions/linkedProjects" },
    "exports": { "$ref": "#/definitions/exports" },
    "dashboard": { "$ref": "#/definitions/dashboard" },
    "integrations": { "$ref": "#/definitions/integrations" },
    "metadata": { "$ref": "#/definitions/metadata" }
  },

  "required": ["id", "documents", "metadata"],

  "definitions": {
    "group": {
      "description": "Linked project level and group.",
      "type": "object",
      "properties": {
        "level": {
          "description": "Group level in linked projects",
          "type": "integer"
        },
        "name": {
          "description": "Group name in linked projects",
          "$ref": "common.json#/definitions/nonEmptyString"
        }
      }
    },
    "metadata": {
      "description": "Project file metadata storing information about the data format version, encryption, etc.",
      "type": "object",
      "properties": {
        "format": {
          "description": "Data format version string",
          "$ref": "common.json#/definitions/nonEmptyString"
        },
        "saveHistory": {
          "description": "Set to true for projects keeping the history of document object changes",
          "type": "boolean"
        },
        "template": {
          "description": "Set for project or document templates",
          "type": "string",
          "enum": ["project", "document"]
        },
        "cipher": {
          "description": "For encrypted files stores the cipher name",
          "const": "aes-256-cbc"
        },
        "iv": {
          "description": "For encrypted files stores the initialization vector",
          "type": "string",
          "pattern": "^[0-9A-Fa-f]{32,}$"
        },
        "salt": {
          "description": "For encrypted files stores the decryption parameter",
          "$ref": "common.json#/definitions/nonEmptyString"
        }
      },
      "required": ["format"]
    },
    "traceability": {
      "description": "Configuration of project traceability links; properties of this object are identifiers of link types",
      "type": "object",
      "propertyNames": {
        "$ref": "common.json#/definitions/nonWhiteSpaceString"
      },
      "additionalProperties": {
        "type": "object",
        "properties": {
          "name": {
            "description": "Link type name",
            "$ref": "common.json#/definitions/nonWhiteSpaceString",
            "examples": ["Reference"]
          },
          "source": {
            "description": "Short text describing the role of the link source",
            "$ref": "common.json#/definitions/nonWhiteSpaceString",
            "examples": ["References"]
          },
          "target": {
            "description": "Short text describing the role of the link target",
            "$ref": "common.json#/definitions/nonWhiteSpaceString",
            "examples": ["Referenced by"]
          },
          "suspect": {
            "type": "array",
            "minItems": 1,
            "uniqueItems": true,
            "items": { "$ref": "common.json#/definitions/nonEmptyString" }
          }
        }
      }
    },
    "linkedProjects": {
      "description": "List of linked projects",
      "type": "array",
      "uniqueItems": true,
      "items": {
        "description": "Linked project properties",
        "type": "object",
        "properties": {
          "projectId": {
            "description": "A unique identifier of the linked project",
            "$ref": "common.json#/definitions/fileName"
          },
          "path": {
            "description": "Relative or absolute path to the linked project",
            "$ref": "common.json#/definitions/filePath"
          }
        },
        "required": ["projectId", "path"]
      }
    },
    "exports": {
      "description": "List of export configurations",
      "type": "array",
      "uniqueItems": true,
      "items": {
        "description": "Export configuration",
        "type": "object",
        "properties": {
          "compactCustomAttributes": {
            "description": "Set to true if displayed custom attributes will be merged into a single column",
            "type": "boolean"
          },
          "docxTemplateFile": {
            "description": "Path to custom DOCX template file",
            "$ref": "common.json#/definitions/filePath"
          },
          "exploreLinkedProjects": {
            "description": "Set to true if linked projects should be loaded before export starts",
            "type": "boolean"
          },
          "exportParamsFile": {
            "description": "Path to custom parameters json file",
            "$ref": "common.json#/definitions/filePath"
          },
          "folding": {
            "description": "Set to true if folding will be ignored",
            "type": "boolean"
          },
          "ignoreFiltering": {
            "description": "Set to true if filtering will be ignored",
            "type": "boolean"
          },
          "ignoreInvisible": {
            "description": "Set to true if links to documents which are not exported will be ignored",
            "type": "boolean"
          },
          "ignoreSorting": {
            "description": "Set to true if sorting will be ignored",
            "type": "boolean"
          },
          "input": {
            "description": "Selected documents for the export",
            "oneOf": [
              {
                "description": "Export document selection",
                "type": "string",
                "enum": ["currentDocument", "openedDocuments", "mainProject", "loadedProjects", "templateSelection"]
              },
              {
                "description": "Array of IDs of exported documents",
                "type": "array",
                "items": {
                  "$ref": "common.json#/definitions/projDocId"
                }
              }
            ]
          },
          "mergeDocuments": {
            "description": "Set to true if exported document will be merged into single file",
            "type": "boolean"
          },
          "name": {
            "description": "Export configuration name",
            "type": "string"
          },
          "pdfSettings": {
            "description": "PDF page settings",
            "type": "object",
            "properties": {
              "landscape": {
                "description": "Set to true if page should have landscape orientation",
                "type": "boolean"
              },
              "marginsType": {
                "description": "The margins of the page",
                "type": "integer",
                "minimum": 0,
                "maximum": 2
              },
              "pageSize": {
                "description": "The size of the page",
                "type": "string",
                "enum": ["A0", "A1", "A2", "A3", "A4", "A5", "Legal", "Letter", "Tabloid", "Ledger"]
              }
            },
            "required": [ "landscape", "marginsType", "pageSize" ]
          },
          "pdfSignCertFile": {
            "description": "Path to PDF certificate file",
            "type": "string"
          },
          "templateFile": {
            "description": "Path to custom layout template file",
            "$ref": "common.json#/definitions/filePath"
          },
          "templateName": {
            "description": "Template layout",
            "type": "string"
          },
          "test": {
            "description": "Export configuration description",
            "type": "string"
          },
          "type": {
            "description": "Export output format",
            "type": "string"
          },
          "view": {
            "description": "Table view used for the export",
            "type": "string"
          }
        },
        "required": ["input", "name"]
      }
    },
    "dashboard": {
      "description": "Dashbard definition",
      "type": "object"
    },
    "integrations": {
      "description": "3rd party integrations config",
      "type": "object",
      "$ref": "common.json#/definitions/integrationsBase",
      "properties": {
        "reqif": {
          "description": "ReqIF integration config",
          "type": "object"
        }
      }
    },
    "hierarchy": {
      "description": "Document groups",
      "type": "array",
      "uniqueItems": true,
      "items": {
        "oneOf": [
          {
            "description": "Document ID",
            "$ref": "common.json#/definitions/fileName"
          },
          {
            "description": "Document group",
            "type": "object",
            "properties": {
              "id": {
                "description": "A unique identifier of the document group",
                "$ref": "common.json#/definitions/nonEmptyString"
              },
              "children": {
                "description": "Array of member document IDs",
                "type": "array",
                "uniqueItems": true,
                "items": {
                  "$ref": "common.json#/definitions/fileName"
                }
              }
            },
            "required": ["id"]
          }
        ]
      }
    }
  }
}
