{
  "$id": "https://dodo.cloud/schemas/app.schema.json",
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "app": {
      "type": "object",
      "oneOf": [
        {
          "$ref": "#/definitions/golang"
        },
        {
          "$ref": "#/definitions/hugo"
        },
        {
          "$ref": "#/definitions/php"
        },
        {
          "$ref": "#/definitions/nextjs-deno2"
        },
        {
          "$ref": "#/definitions/nodejs"
        }
      ]
    },
	"volume": {
	  "$ref": "#/definitions/volumes"
	},
	"postgresql": {
	  "$ref": "#/definitions/postgresql"
	},
	"mongodb": {
	  "$ref": "#/definitions/mongodb"
	}
  },
  "definitions": {
    "golang": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "oneOf": [
            {
              "const": "golang:1.22.0"
            },
            {
              "const": "golang:1.20.0"
            }
          ]
        },
        "run": {
          "type": "string"
        },
        "ingress": {
          "$ref": "#/definitions/ingress"
        },
        "dev": {
          "$ref": "#/definitions/dev"
        }
      },
      "additionalProperties": false,
      "required": [
        "type"
      ]
    },
    "hugo": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "oneOf": [
            {
              "const": "hugo:latest"
            }
          ]
        },
        "ingress": {
          "$ref": "#/definitions/ingress"
        },
        "dev": {
          "$ref": "#/definitions/dev"
        }
      },
      "additionalProperties": false,
      "required": [
        "type"
      ]
    },
    "php": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "oneOf": [
            {
              "const": "php:8.2-apache"
            }
          ]
        },
        "ingress": {
          "$ref": "#/definitions/ingress"
        },
        "dev": {
          "$ref": "#/definitions/dev"
        }
      },
      "additionalProperties": false,
      "required": [
        "type"
      ]
    },
    "nextjs-deno2": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "oneOf": [
            {
              "const": "nextjs:deno-2.0.0"
            }
          ]
        },
        "ingress": {
          "$ref": "#/definitions/ingress"
        },
        "dev": {
          "$ref": "#/definitions/dev"
        },
        "preBuildCommands": {
          "$ref": "#/definitions/commands"
        }
      },
      "additionalProperties": false,
      "required": [
        "type"
      ]
    },
    "nodejs": {
      "type": "object",
      "properties": {
        "type": {
          "type": "string",
          "oneOf": [
            {
              "const": "nodejs-23.1.0"
            }
          ]
        },
        "ingress": {
          "$ref": "#/definitions/ingress"
        },
        "dev": {
          "$ref": "#/definitions/dev"
        },
        "preBuildCommands": {
          "$ref": "#/definitions/commands"
        }
      },
      "additionalProperties": false,
      "required": [
        "type"
      ]
    },
    "dev": {
      "type": "object",
      "properties": {
        "enabled": { "type": "boolean" },
        "user": { "type": "string" },
        "additionalProperties": false,
        "required": [
          "enabled"
        ]
      }
    },
    "volume": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        },
        "size": {
          "$ref": "#/definitions/size"
        }
      },
      "additionalProperties": false,
      "required": [
        "name",
        "size"
      ]
    },
    "volumes": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/volume"
      }
    },
    "postgre": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        },
        "size": {
          "$ref": "#/definitions/size"
        }
      },
      "additionalProperties": false,
      "required": [
        "name",
        "size"
      ]
    },
    "postgresql": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/postgre"
      }
    },
    "size": {
      "type": "string",
      "pattern": "[1-9][0-9]*(Mi|Gi)"
    },
    "ingress": {
      "type": "object",
      "properties": {
        "network": {
          "type": "string",
          "oneOf": {{ .Networks }}
        },
        "subdomain": {
          "type": "string",
          "minLength": 1
        },
        "auth": {
          "type": "object",
          "oneOf": [
            {
              "type": "object",
              "properties": {
                "enabled": {
                  "enum": [
                    false
                  ]
                }
              },
              "additionalProperties": false,
              "required": [
                "enabled"
              ]
            },
            {
              "type": "object",
              "properties": {
                "enabled": {
                  "enum": [
                    true
                  ]
                },
                "groups": {
                  "type": "string"
                },
                "noAuthPathPatterns": {
                  "type": "array",
                  "items": { "type": "string" }
                }
              },
              "additionalProperties": false,
              "required": [
                "enabled"
              ]
            }
          ]
        }
      },
      "additionalProperties": false,
      "required": [
        "network",
        "subdomain"
      ]
    },
	// mongo start
    "mongo": {
      "type": "object",
      "properties": {
        "name": {
          "type": "string"
        },
        "size": {
          "$ref": "#/definitions/size"
        },
		"initdbScripts": { "type": "object" }
      },
      "additionalProperties": false,
      "required": [
        "name",
        "size"
      ]
    },
    "mongodb": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/mongo"
      }
    },
    "size": {
      "type": "string",
      "pattern": "[1-9][0-9]*(Mi|Gi)"
    },
    "ingress": {
      "type": "object",
      "properties": {
        "network": {
          "type": "string",
          "oneOf": {{ .Networks }}
        },
        "subdomain": {
          "type": "string",
          "minLength": 1
        },
        "auth": {
          "type": "object",
          "oneOf": [
            {
              "type": "object",
              "properties": {
                "enabled": {
                  "enum": [
                    false
                  ]
                }
              },
              "additionalProperties": false,
              "required": [
                "enabled"
              ]
            },
            {
              "type": "object",
              "properties": {
                "enabled": {
                  "enum": [
                    true
                  ]
                },
                "groups": {
                  "type": "string"
                },
                "noAuthPathPatterns": {
                  "type": "array",
                  "items": { "type": "string" }
                }
              },
              "additionalProperties": false,
              "required": [
                "enabled"
              ]
            }
          ]
        }
      },
      "additionalProperties": false,
      "required": [
        "network",
        "subdomain"
      ]
    },

    "command": {
      "type": "object",
      "properties": {
        "bin": { "type": "string" },
        "args": {
          "type": "array",
          "items": { "type": "string" }
        },
        "env": {
          "type": "array",
          "items": { "type": "string" }
        }
      },
      "additionalProperties": false,
      "required": ["bin"]
    },
    "commands": {
      "type": "array",
      "items": {
        "$ref": "#/definitions/command"
      }
    }
  }
}
