{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "description": "Sparks.Network data model",
    "type": "object",
    "required": [
        "project",
        "opp",
        "contrib",
        "benefit",
        "team",
        "oppAllowedTeam"
    ],
    "additionalProperties": false,
    "properties": {
        "project": {
            "type": "object",
            "patternProperties": {
                "^[a-zA-Z0-9-_]+$": {
                    "type": "object",
                    "$ref": "#/definitions/projectDef"
                }
            }
        },
        "profile": {
            "type": "object",
            "patternProperties": {
                "^[a-zA-Z0-9-_]+$": {
                    "type": "object",
                    "$ref": "#/definitions/profileDef"
                }
            }
        },
        "opp": {
            "type": "object",
            "patternProperties": {
                "^[a-zA-Z0-9-_]+$": {
                    "type": "object",
                    "$ref": "#/definitions/oppDef"
                }
            }
        },
        "contrib": {
            "type": "object",
            "patternProperties": {
                "^[a-zA-Z0-9-_]+$": {
                    "type": "object",
                    "$ref": "#/definitions/contribDef"
                }
            }
        },
        "benefit": {
            "type": "object",
            "patternProperties": {
                "^[a-zA-Z0-9-_]+$": {
                    "type": "object",
                    "$ref": "#/definitions/benefitDef"
                }
            }
        },
        "team": {
            "type": "object",
            "patternProperties": {
                "^[a-zA-Z0-9-_]+$": {
                    "type": "object",
                    "$ref": "#/definitions/teamDef"
                }
            }
        },
        "oppAllowedTeam": {
            "type": "object",
            "patternProperties": {
                "^[a-zA-Z0-9-_]+$": {
                    "type": "object",
                    "$ref": "#/definitions/oppAllowedTeamDef"
                }
            }
        },
        "applicationTeam": {
            "type": "object",
            "patternProperties": {
                "^[a-zA-Z0-9-_]+$": {
                    "type": "object",
                    "$ref": "#/definitions/applicationTeamDef"
                }
            }
        },
        "application": {
            "type": "object",
            "patternProperties": {
                "^[a-zA-Z0-9-_]+$": {
                    "type": "object",
                    "$ref": "#/definitions/applicationDef"
                }
            }
        },
        "shift": {
            "type": "object",
            "patternProperties": {
                "^[a-zA-Z0-9-_]+$": {
                    "type": "object",
                    "$ref": "#/definitions/shiftDef"
                }
            }
        },
        "applicationShift": {
            "type": "object",
            "patternProperties": {
                "^[a-zA-Z0-9-_]+$": {
                    "type": "object",
                    "$ref": "#/definitions/applicationShiftDef"
                }
            }
        }
    },
    "definitions": {
        "profileDef": {},
        "projectDef": {
            "required": [
                "title",
                "description",
                "startDateTime",
                "location",
                "organizer",
                "maxKarmaPoints",
                "images",
                "projectPageUrl"
            ],
            "additionalProperties": false,
            "properties": {
                "title": {
                    "$ref": "#/constraints/nonEmptyString"
                },
                "description": {
                    "$ref": "#/constraints/nonEmptyString"
                },
                "projectType": {
                    "type": "string",
                    "enum": [
                        "Simple",
                        "MultiDay",
                        "LongTerm",
                        "Donor"
                    ]
                },
                "startDateTime": {
                    "type": "string",
                    "format": "date-time"
                },
                "endDateTime": {
                    "type": "string",
                    "format": "date-time"
                },
                "location": {
                    "type": "object",
                    "properties": {
                        "name": {
                            "type": "string"
                        },
                        "address": {
                            "type": "string"
                        },
                        "city": {
                            "type": "string"
                        },
                        "state": {
                            "type": "string"
                        },
                        "latitude": {
                            "type": "number"
                        },
                        "longitude": {
                            "type": "number"
                        }
                    }
                },
                "images": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "required": [
                            "imageUrl"
                        ],
                        "properties": {
                            "imageUrl": {
                                "type": "string",
                                "format": "uri"
                            }
                        }
                    }
                },
                "maxKarmaPoints": {
                    "type": "integer"
                },
                "shareKarmaPoints": {
                    "type": "integer"
                },
                "organizer": {
                    "type": "object",
                    "required": [
                        "organizerKey",
                        "name",
                        "organization"
                    ],
                    "properties": {
                        "organizerKey": {
                            "$ref": "#/constraints/nonEmptyString"
                        },
                        "name": {
                            "$ref": "#/constraints/nonEmptyString"
                        },
                        "organization": {
                            "$ref": "#/constraints/nonEmptyString"
                        },
                        "imageUrl": {
                            "type": "string",
                            "format": "uri"
                        }
                    }
                },
                "projectPageUrl": {
                    "type": "string",
                    "format": "uri"
                },
                "communityBenefit": {
                    "type": "string"
                },
                "facebookUrl": {
                    "$ref": "#/constraints/nonEmptyString"
                },
                "twitterUrl": {
                    "$ref": "#/constraints/nonEmptyString"
                }
            }
        },
        "oppDef": {
            "required": [
                "projectKey",
                "title",
                "description"
            ],
            "additionalProperties": false,
            "properties": {
                "projectKey": {
                    "$ref": "#/constraints/nonEmptyString"
                },
                "title": {
                    "$ref": "#/constraints/nonEmptyString"
                },
                "description": {
                    "$ref": "#/constraints/nonEmptyString"
                },
                "question": {
                    "type": "string"
                },
                "icon": {
                    "type": "string"
                },
                "karma": {
                    "type": "integer"
                },
                "contribValue": {
                    "type": "number"
                },
                "benefitValue": {
                    "type": "number"
                }
            }
        },
        "contribDef": {
            "required": [
                "oppKey",
                "title",
                "description"
            ],
            "additionalProperties": false,
            "properties": {
                "oppKey": {
                    "$ref": "#/constraints/nonEmptyString"
                },
                "type": {
                    "type": "string",
                    "enum": [
                        "Shift",
                        "PrePayment",
                        "Deposit",
                        "Donation"
                    ]
                },
                "count": {
                    "type": "integer"
                },
                "title": {
                    "$ref": "#/constraints/nonEmptyString"
                },
                "description": {
                    "$ref": "#/constraints/nonEmptyString"
                },
                "icon": {
                    "type": "string"
                },
                "shiftMinLength": {
                    "type": "integer"
                },
                "shiftMaxLength": {
                    "type": "integer"
                }
            }
        },
        "benefitDef": {
            "required": [
                "oppKey",
                "title",
                "description"
            ],
            "additionalProperties": false,
            "properties": {
                "oppKey": {
                    "$ref": "#/constraints/nonEmptyString"
                },
                "type": {
                    "type": "string",
                    "enum": [
                        "FoodTicket",
                        "EventTicket",
                        "Gifts",
                        "FoodDrink",
                        "HelpNonProfit"
                    ]
                },
                "title": {
                    "$ref": "#/constraints/nonEmptyString"
                },
                "description": {
                    "$ref": "#/constraints/nonEmptyString"
                },
                "icon": {
                    "type": "string"
                },
                "value": {
                    "type": "number"
                }
            }
        },
        "teamDef": {
            "required": [
                "title",
                "description"
            ],
            "additionalProperties": false,
            "properties": {
                "title": {
                    "$ref": "#/constraints/nonEmptyString"
                },
                "description": {
                    "$ref": "#/constraints/nonEmptyString"
                },
                "question": {
                    "$ref": "#/constraints/nonEmptyString"
                },
                "icon": {
                    "type": "string"
                }
            }
        },
        "oppAllowedTeamDef": {
            "required": [
                "oppKey",
                "teamKey"
            ],
            "additionalProperties": false,
            "properties": {
                "oppKey": {
                    "$ref": "#/constraints/nonEmptyString"
                },
                "teamKey": {
                    "$ref": "#/constraints/nonEmptyString"
                },
                "team": {
                    "type": "object",
                    "required": [
                        "title",
                        "description"
                    ],
                    "properties": {
                        "title": {
                            "$ref": "#/constraints/nonEmptyString"
                        },
                        "description": {
                            "$ref": "#/constraints/nonEmptyString"
                        },
                        "icon": {
                            "type": "string"
                        }
                    }
                }
            }
        },
        "applicationTeamDef": {
            "required": [
                "appKey",
                "teamKey",
                "joinedOn"
            ],
            "additionalProperties": false,
            "properties": {
                "appKey": {
                    "$ref": "#/constraints/nonEmptyString"
                },
                "teamKey": {
                    "$ref": "#/constraints/nonEmptyString"
                },
                "question": {
                    "$ref": "#/constraints/nonEmptyString"
                },
                "answer": {
                    "$ref": "#/constraints/nonEmptyString"
                },
                "joinedOn": {
                    "type": "string",
                    "format": "date-time"
                }
            }
        },
        "applicationDef": {
            "required": [
                "oppKey",
                "projectKey",
                "profileKey",
                "status",
                "createdOn"
            ],
            "additionalProperties": false,
            "properties": {
                "oppKey": {
                    "$ref": "#/constraints/nonEmptyString"
                },
                "profileKey": {
                    "$ref": "#/constraints/nonEmptyString"
                },
                "projectKey": {
                    "$ref": "#/constraints/nonEmptyString"
                },
                "status": {
                    "type": "string",
                    "enum": [
                        "Incomplete",
                        "Pending",
                        "Accepted",
                        "Canceled"
                    ]
                },
                "oppQuestion": {
                    "$ref": "#/constraints/nonEmptyString"
                },
                "oppAnswer": {
                    "$ref": "#/constraints/nonEmptyString"
                },
                "step": {
                    "type": "string",
                    "enum": [
                        "Answer",
                        "Team"
                    ]
                },
                "createdOn": {
                    "type": "string",
                    "format": "date-time"
                },
                "submittedOn": {
                    "type": "string",
                    "format": "date-time"
                },
                "acceptedOn": {
                    "type": "string",
                    "format": "date-time"
                },
                "canceledOn": {
                    "type": "string",
                    "format": "date-time"
                }
            }
        },
        "shiftDef": {
            "required": [
                "startDateTime",
                "teamKey",
                "teamTitle"
            ],
            "additionalProperties": false,
            "properties": {
                "startDateTime": {
                    "type": "string",
                    "format": "date-time"
                },
                "endDateTime": {
                    "type": "string",
                    "format": "date-time"
                },
                "teamKey": {
                    "$ref": "#/constraints/nonEmptyString"
                },
                "teamTitle": {
                    "$ref": "#/constraints/nonEmptyString"
                },
                "teamIcon": {
                    "type": "string"
                }
            }
        },
        "applicationShiftDef": {
            "required": [
                "appKey",
                "shiftKey",
                "joinedOn"
            ],
            "properties": {
                "appKey": {
                    "$ref": "#/constraints/nonEmptyString"
                },
                "shiftKey": {
                    "$ref": "#/constraints/nonEmptyString"
                },
                "joinedOn": {
                    "type": "string",
                    "format": "date-time"
                }
            }
        }
    },
    "constraints": {
        "nonEmptyString": {
            "type": "string",
            "minLength": 1
        }
    }
}