{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "title": "Config app mobile OTO Enterprise OS (Expo/EAS + navigation par rôle)",
  "type": "object",
  "additionalProperties": false,
  "required": ["app_config", "eas_build", "role_navigation", "manifest"],
  "properties": {
    "app_config": {
      "type": "object",
      "additionalProperties": false,
      "required": ["expo"],
      "properties": {
        "expo": {
          "type": "object",
          "additionalProperties": false,
          "required": [
            "name", "slug", "scheme", "version", "orientation",
            "userInterfaceStyle", "backgroundColor", "primaryColor", "icon",
            "splash", "locales", "ios", "android", "extra", "plugins"
          ],
          "properties": {
            "name": {"type": "string", "minLength": 1},
            "slug": {"type": "string", "minLength": 1},
            "scheme": {"type": "string", "minLength": 1},
            "version": {"type": ["string", "null"]},
            "orientation": {"type": "string", "enum": ["portrait", "landscape", "default"]},
            "userInterfaceStyle": {"type": "string", "enum": ["dark", "light", "automatic"]},
            "backgroundColor": {"type": "string", "pattern": "^#[0-9a-fA-F]{6}$"},
            "primaryColor": {"type": "string", "pattern": "^#[0-9a-fA-F]{6}$"},
            "icon": {"type": ["string", "null"]},
            "splash": {
              "type": "object",
              "additionalProperties": false,
              "required": ["backgroundColor", "resizeMode", "image"],
              "properties": {
                "backgroundColor": {"type": "string", "pattern": "^#[0-9a-fA-F]{6}$"},
                "resizeMode": {"type": "string", "enum": ["contain", "cover"]},
                "image": {"type": ["string", "null"]}
              }
            },
            "locales": {"type": "object"},
            "ios": {
              "type": "object",
              "additionalProperties": false,
              "required": ["bundleIdentifier", "buildNumber", "supportsTablet"],
              "properties": {
                "bundleIdentifier": {"type": ["string", "null"]},
                "buildNumber": {"type": ["string", "null"]},
                "supportsTablet": {"type": "boolean"}
              }
            },
            "android": {
              "type": "object",
              "additionalProperties": false,
              "required": ["package", "versionCode"],
              "properties": {
                "package": {"type": ["string", "null"]},
                "versionCode": {"type": ["integer", "null"]}
              }
            },
            "extra": {
              "type": "object",
              "additionalProperties": false,
              "required": ["expoSdkMajor", "defaultLocale", "devises", "eas"],
              "properties": {
                "expoSdkMajor": {"type": "integer", "minimum": 1},
                "defaultLocale": {"type": "string", "minLength": 1},
                "devises": {"type": "array", "minItems": 2, "items": {"type": "string"}},
                "eas": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": ["projectId"],
                  "properties": {"projectId": {"type": ["string", "null"]}}
                }
              }
            },
            "plugins": {"type": "array"}
          }
        }
      }
    },
    "eas_build": {
      "type": "object",
      "additionalProperties": false,
      "required": ["cli", "build", "submit"],
      "properties": {
        "cli": {
          "type": "object",
          "additionalProperties": false,
          "required": ["version", "appVersionSource"],
          "properties": {
            "version": {"type": ["string", "null"]},
            "appVersionSource": {"type": "string", "enum": ["remote", "local"]}
          }
        },
        "build": {
          "type": "object",
          "additionalProperties": false,
          "required": ["development", "preview", "production"],
          "properties": {
            "development": {"type": "object"},
            "preview": {"type": "object"},
            "production": {"type": "object"}
          }
        },
        "submit": {
          "type": "object",
          "additionalProperties": false,
          "required": ["production"],
          "properties": {
            "production": {
              "type": "object",
              "additionalProperties": false,
              "required": ["ios", "android"],
              "properties": {
                "ios": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": ["appleId", "ascAppId", "appleTeamId"],
                  "properties": {
                    "appleId": {"type": ["string", "null"]},
                    "ascAppId": {"type": ["string", "null"]},
                    "appleTeamId": {"type": ["string", "null"]}
                  }
                },
                "android": {
                  "type": "object",
                  "additionalProperties": false,
                  "required": ["serviceAccountKeyPath", "track"],
                  "properties": {
                    "serviceAccountKeyPath": {"type": ["string", "null"]},
                    "track": {"type": "string", "enum": ["internal", "alpha", "beta", "production"]}
                  }
                }
              }
            }
          }
        }
      }
    },
    "role_navigation": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": ["portail", "label", "icon", "route", "roles_allowed", "n_roles"],
        "properties": {
          "portail": {"type": "string", "minLength": 1},
          "label": {"type": "string", "minLength": 1},
          "icon": {"type": "string", "minLength": 1},
          "route": {"type": "string", "pattern": "^/[a-z]+$"},
          "roles_allowed": {"type": "array", "minItems": 1, "items": {"type": "string"}, "uniqueItems": true},
          "n_roles": {"type": "integer", "minimum": 1}
        }
      }
    },
    "manifest": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "generated_from", "spec_version", "source_version", "roadmap_ref",
        "app", "counts", "brand", "devises", "langues", "a_confirmer",
        "identifiants_statut", "portails", "hand_off"
      ],
      "properties": {
        "generated_from": {"type": "string"},
        "spec_version": {"type": "string"},
        "source_version": {"type": "string"},
        "roadmap_ref": {"type": "string"},
        "app": {
          "type": "object",
          "additionalProperties": false,
          "required": ["name", "slug", "scheme", "expo_sdk_major"],
          "properties": {
            "name": {"type": "string"},
            "slug": {"type": "string"},
            "scheme": {"type": "string"},
            "expo_sdk_major": {"type": "integer"}
          }
        },
        "counts": {
          "type": "object",
          "additionalProperties": false,
          "required": ["onglets", "portails", "roles_couverts", "langues", "identifiants_a_confirmer"],
          "properties": {
            "onglets": {"type": "integer", "minimum": 0},
            "portails": {"type": "integer", "minimum": 0},
            "roles_couverts": {"type": "integer", "minimum": 0},
            "langues": {"type": "integer", "minimum": 0},
            "identifiants_a_confirmer": {"type": "integer", "minimum": 0}
          }
        },
        "brand": {
          "type": "object",
          "additionalProperties": false,
          "required": ["fond", "accent"],
          "properties": {
            "fond": {
              "type": "object",
              "additionalProperties": false,
              "required": ["valeur", "source"],
              "properties": {"valeur": {"type": "string"}, "source": {"type": "string"}}
            },
            "accent": {
              "type": "object",
              "additionalProperties": false,
              "required": ["valeur", "source"],
              "properties": {"valeur": {"type": "string"}, "source": {"type": "string"}}
            }
          }
        },
        "devises": {
          "type": "object",
          "additionalProperties": false,
          "required": ["primaire", "secondaire", "source"],
          "properties": {
            "primaire": {"type": "string"},
            "secondaire": {"type": "string"},
            "source": {"type": "string"}
          }
        },
        "langues": {
          "type": "object",
          "additionalProperties": false,
          "required": ["liste", "defaut", "source"],
          "properties": {
            "liste": {"type": "array", "minItems": 1, "items": {"type": "string"}},
            "defaut": {"type": "string"},
            "source": {"type": "string"}
          }
        },
        "a_confirmer": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["champ", "raison"],
            "properties": {"champ": {"type": "string"}, "raison": {"type": "string"}}
          }
        },
        "identifiants_statut": {"type": "string", "const": "a_confirmer"},
        "portails": {
          "type": "array",
          "minItems": 1,
          "items": {
            "type": "object",
            "additionalProperties": false,
            "required": ["portail", "label", "icon", "nb_roles"],
            "properties": {
              "portail": {"type": "string"},
              "label": {"type": "string"},
              "icon": {"type": "string"},
              "nb_roles": {"type": "integer", "minimum": 0}
            }
          }
        },
        "hand_off": {"type": "string"}
      }
    }
  }
}
