{
    "$schema": "http://json-schema.org/draft-07/schema#",
    "$id": "https://www.spmhome.io/product/app-publisher/schema/latest/spmh.ap.schema.json",
    "description": "App-Publisher .aprc configuration file schema",
    "title": "ApSchema",
    "type": "object",
    "additionalProperties": true,
    "required": [
        "projectName"
    ],
    "properties": {
        "$schema": {
            "type": "string",
            "pattern": "^.+?\\/(?:[a-z0-9_\\-]+\\.)+schema\\.json$"
        },
        "projectName": {
            "type": "string",
            "maxLength": 32,
            "pattern": "^[\\w-\\.]+$"
        },
        "projectSlug": {
            "type": "string",
            "maxLength": 32,
            "pattern": "^[a-z][a-z0-9_-\\.]+$"
        },
        "projectType": {
            "$ref": "#/definitions/ApProjectType"
        },
        "commitMsgMap": {
            "$ref": "#/definitions/ApCommitMsgMap"
        },
        "httpRelease": {
            "$ref": "#/definitions/ApConfigFlag"
        },
        "serviceWorker": {
            "$ref": "#/definitions/ApNgServiceWorkerConfig"
        }
    },
    "definitions":
    {
        "BooleanDefaultFalse": {
            "$id": "#/BooleanDefaultFalse",
            "type": "boolean",
            "default": false
        },
        "BooleanDefaultTrue": {
            "$id": "#/BooleanDefaultTrue",
            "type": "boolean",
            "default": true
        },
        "BooleanReadOnly": {
            "$id": "#/BooleanReadOnly",
            "type": "boolean",
            "readOnly": true,
            "default": false
        },
        "BooleanYesNo": {
            "$id": "#/BooleanYesNo",
            "type": "string",
            "default": "N",
            "minLength": 1,
            "maxLength": 1,
            "enum": [
                "Y", "N"
            ]
        },
        "BooleanYesNoDefaultYes": {
            "$id": "#/BooleanYesNoDefaultYes",
            "type": "string",
            "default": "Y",
            "minLength": 1,
            "maxLength": 1,
            "enum": [
                "Y", "N"
            ]
        },
        "DirectoryPathRelative": {
            "$id": "#/DirectoryPathRelative",
            "type": "string",
            "maxLength": 100,
            "description": "relative path to a directory",
            "pattern": "^(?:#\\{[\\w_\\-\\.]+?\\}[\\w\\.\\-\\\\/]*?|(?:\\.{1,2}[\\\\/][\\w\\.\\-\\\\/]+|\\.\\.?))$",
            "if": {
                "pattern": "^\\.$"
            },
            "then": {
                "minLength": 1
            },
            "else": {
                "minLength": 3
            }
        },
        "DirectoryPath": {
            "$id": "#/DirectoryPath",
            "type": "string",
            "maxLength": 150,
            "description": "relative or absolute path to a directory",
            "pattern": "^(?:\\.{1,2}|(?:\\.[\\\\/])?[\\w][~@!:\\*\\w\\.\\-\\\\/:]+)$",
            "if": {
                "pattern": "^\\.$"
            },
            "then": {
                "minLength": 1
            },
            "else": {
                "minLength": 3
            }
        },
        "DirectoryPathGlob": {
            "$id": "#/DirectoryPathGlob",
            "type": "string",
            "minLength": 4,
            "description": "directory type glob path",
            "pattern": "^(?:\\.{1,2}[\\\\/])\\*{0,2}(?:\\.|(?:\\.[\\\\/])?[\\w][~@!\\w\\.\\-\\\\/]+)\\*{0,2}$",
            "if": {
                "pattern": "^\\.{1,2}[\\\\/]"
            },
            "then": {
                "if": {
                    "pattern": "^\\.\\.[\\\\/]\\*{0,2}[\\\\/]"
                },
                "then": {
                    "minLength": 5
                },
                "else": {
                    "minLength": 3
                }
            },
            "else": {
                "minLength": 1
            }
        },
        "FileName": {
            "$id": "#/FileName",
            "type": "string",
            "minLength": 3,
            "maxLength": 150,
            "pattern": "^[\\w\\.\\-]+\\.(?:[cm]?jsx?|tsx?|d\\.ts|[a-z0-9]{2,4})$",
            "description": "a valid filename, without path, e.g 'main.js', 'app.tsx', etc"
        },
        "FileOrDirectoryPath": {
            "$id": "#/FileOrDirectoryPath",
            "anyOf": [{
                "$ref": "#/definitions/DirectoryPath"
            },
            {
                "$ref": "#/definitions/FilePath"
            }]
        },
        "FileOrDirectoryPaths": {
            "$id": "#/FileOrDirectoryPaths",
            "oneOf": [{
                "$ref": "#/definitions/FileOrDirectoryPath"
            },
            {
                "type": "array",
                "items": {
                    "$ref": "#/definitions/FileOrDirectoryPath"
                }
            }]
        },
        "FilePath": {
            "$id": "#/FilePath",
            "type": "string",
            "minLength": 5,
            "maxLength": 150,
            "description": "relative or absolute path to a file",
            "pattern": "^(?:(?:\\.[\\\\/])?[~@!:\\*\\w\\.\\-\\\\/]+)?\\.[a-z0-9\\.]+$"
        },
        "FilePathJs": {
            "$id": "#/FilePathJs",
            "$ref": "#/definitions/FilePath",
            "description": "relative or absolute path to a javascript (module) file",
            "pattern": "^(?:(?:\\.[\\\\/])?[~@!:\\w\\.\\-\\\\/]+)?\\.js$"
        },
        "FilePathJson": {
            "$id": "#/FilePathJson",
            "$ref": "#/definitions/FilePath",
            "description": "relative or absolute path to a json file",
            "pattern": "^(?:(?:\\.[\\\\/])?[~@!:\\w\\.\\-\\\\/]+)?\\.json$"
        },
        "FilePathRelativeLeadingDot": {
            "$id": "#/FilePathRelativeLeadingDot",
            "type": "string",
            "minLength": 6,
            "maxLength": 150,
            "description": "relative path to a file, with leading ./ or .\\",
            "pattern": "^\\.{1,2}[\\\\/][\\w\\.\\-\\\\/]+?\\.\\w+$"
        },
        "FilePathRelative": {
            "$id": "#/FilePathRelative",
            "type": "string",
            "minLength": 5,
            "maxLength": 150,
            "description": "relative path to a file",
            "pattern": "^\\.[\\\\/][\\w\\.\\-\\\\/]+\\.([cm]?jsx?|tsx?)$"
        },
        "SemanticVersion": {
            "$id": "#/VersionAndOrPreReleaseVersion",
            "type": "string",
            "minLength": 5,
            "maxLength": 28,
            "description": "semantic version string",
            "pattern": "^[0-9]{,3}\\.[0-9]{,4}\\.[0-9]{,5}(?:\\-[a-z]{,8}\\.[0-9]{,5})?$"
        },
        "ApCommitMsgMap": {
            "type": "object",
            "additionalProperties": {
                "type": "object",
                "properties": {
                    "formatText": {
                        "type": "string"
                    },
                    "iconCls": {
                        "type": "string",
                        "pattern": "^fa-[a-z0-9_\\-]+$"
                    },
                    "include": {
                        "type": "boolean"
                    },
                    "versionBump": {
                        "oneOf": [{
                            "const": "patch"
                        },{
                            "const": "minor"
                        },{
                            "const": "major"
                        }]
                    }
                }
            }
        },
        "ApConfigFlag": {
            "$id": "#/ApConfigFlag",
            "oneOf": [{
                "const": "Y"
            },
            {
                "const": "N"

            }]
        },
        "ApHttpRelease": {
            "type": "object",
            "properties": {
                "changelog": {
                    "localDst": {
                        "$ref": "#/definitions/DirectoryPath"
                    },
                    "remoteDst": {
                        "$ref": "#/definitions/DirectoryPath"
                    }
                },
                "endpoint": {
                    "type": "string"
                },
                "license": {
                    "localSrc": {
                        "$ref": "#/definitions/FilePath"
                    },
                    "remoteDst": {
                        "$ref": "#/definitions/DirectoryPath"
                    }
                },
                "readme": {
                    "localSrc": {
                        "$ref": "#/definitions/FilePath"
                    },
                    "remoteDst": {
                        "$ref": "#/definitions/DirectoryPath"
                    }
                },
                "token": {
                    "type": "string"
                },
                "zip": {
                    "type": "object",
                    "properties": {
                        "localSrc": {
                            "$ref": "#/definitions/DirectoryPath"
                        },
                        "remoteDst": {
                            "$ref": "#/definitions/DirectoryPath"
                        }
                    }
                }
            }
        },
        "ApNgServiceWorkerConfig": {
            "type": "object",
            "properties": {
                "appVersion": {
                    "$ref": "#/definitions/SemanticVersion"
                },
                "svrVersion":  {
                    "$ref": "#/definitions/SemanticVersion"
                },
                "ngVersion": {
                    "$ref": "#/definitions/SemanticVersion"
                },
                "debug":  {
                    "type": "boolean"
                },
                "debugColor":  {
                    "type": "string",
                    "minLength": 3,
                    "maxLength": 20
                },
                "defaultTheme":  {
                    "type": "string",
                    "minLength": 3,
                    "maxLength": 20
                },
                "directoryIndex": {
                    "$ref": "#/definitions/FilePath"
                },
                "importScripts": {
                    "type": "array",
                    "items": {
                        "$ref": "#/definitions/FilePathRelative"
                    }
                },
                "maximumFileSizeToCacheInBytes": {
                    "type": "number",
                    "default": 8388608
                },
                "preCachingCfg": {
                    "type": "object",
                    "properties": {}
                }
            }
        },
        "ApProjectType": {
            "$id": "#/ApProjectType",
            "oneOf": [{
                "const": "app"
            },
            {
                "const": "library"
            },
            {
                "const": "ng-module"
            },
            {
                "const": "shell"
            },
            {
                "const": "webapp"
            },
            {
                "const": "webclient"
            },
            {
                "const": "webserver"
            }]
        }
    }
}