{
  "namespace" : "salepiper",
  "version" : 1,
  "types" : {
    "person" : {
      "kind" : "entity",
      "schema" : {
        "type" : "object",
        "properties" : {
          "name" : {
            "type" : "string",
            "minLength" : 1,
            "maxLength" : 160
          },
          "email" : {
            "type" : "string",
            "maxLength" : 254
          }
        },
        "required" : [ "name" ],
        "additionalProperties" : false
      }
    },
    "agent" : {
      "kind" : "entity",
      "schema" : {
        "type" : "object",
        "properties" : {
          "name" : {
            "type" : "string",
            "minLength" : 1,
            "maxLength" : 160
          },
          "description" : {
            "type" : "string",
            "maxLength" : 1000
          }
        },
        "required" : [ "name" ],
        "additionalProperties" : false
      }
    },
    "organization" : {
      "kind" : "entity",
      "schema" : {
        "type" : "object",
        "properties" : {
          "name" : {
            "type" : "string",
            "minLength" : 1,
            "maxLength" : 160
          }
        },
        "required" : [ "name" ],
        "additionalProperties" : false
      }
    },
    "deal" : {
      "kind" : "relationship",
      "schema" : {
        "type" : "object",
        "properties" : {
          "title" : {
            "type" : "string",
            "minLength" : 1,
            "maxLength" : 160
          },
          "amount" : {
            "type" : "number",
            "minimum" : 0
          },
          "currency" : {
            "type" : "string",
            "maxLength" : 3
          },
          "evidence" : {
            "type" : "string",
            "minLength" : 1,
            "maxLength" : 2000
          }
        },
        "required" : [ "title" ],
        "additionalProperties" : false
      },
      "roles" : {
        "representative" : {
          "min" : 0,
          "max" : 20,
          "types" : [ "salepiper/person", "salepiper/agent" ]
        },
        "buyer" : {
          "min" : 1,
          "max" : 1,
          "types" : [ "salepiper/organization" ]
        },
        "seller" : {
          "min" : 1,
          "max" : 1,
          "types" : [ "salepiper/organization" ]
        },
        "champion" : {
          "min" : 0,
          "max" : 10,
          "types" : [ "salepiper/person" ]
        }
      },
      "lifecycle" : {
        "initial" : "identified",
        "states" : [ "identified", "qualifying", "proposal", "won", "lost" ]
      },
      "commands" : {
        "qualify" : {
          "input" : {
            "type" : "object",
            "properties" : {
              "evidence" : {
                "type" : "string",
                "minLength" : 1,
                "maxLength" : 2000
              }
            },
            "required" : [ "evidence" ],
            "additionalProperties" : false
          },
          "from" : [ "identified" ],
          "to" : "qualifying",
          "guard" : {
            "present" : {
              "path" : [ "input", "evidence" ]
            }
          },
          "set_data" : {
            "evidence" : {
              "path" : [ "input", "evidence" ]
            }
          }
        },
        "propose" : {
          "input" : {
            "type" : "object",
            "properties" : { },
            "required" : [ ],
            "additionalProperties" : false
          },
          "from" : [ "qualifying" ],
          "to" : "proposal",
          "guard" : {
            "present" : {
              "path" : [ "data", "evidence" ]
            }
          },
          "emit" : [ {
            "kind" : "work.requested",
            "task" : "Prepare a proposal for review. External actions require separate authorization."
          } ]
        },
        "win" : {
          "input" : {
            "type" : "object",
            "properties" : {
              "evidence" : {
                "type" : "string",
                "minLength" : 1,
                "maxLength" : 2000
              }
            },
            "required" : [ "evidence" ],
            "additionalProperties" : false
          },
          "from" : [ "proposal" ],
          "to" : "won",
          "set_data" : {
            "evidence" : {
              "path" : [ "input", "evidence" ]
            }
          }
        },
        "lose" : {
          "input" : {
            "type" : "object",
            "properties" : {
              "evidence" : {
                "type" : "string",
                "minLength" : 1,
                "maxLength" : 2000
              }
            },
            "required" : [ "evidence" ],
            "additionalProperties" : false
          },
          "from" : [ "identified", "qualifying", "proposal" ],
          "to" : "lost",
          "set_data" : {
            "evidence" : {
              "path" : [ "input", "evidence" ]
            }
          }
        }
      }
    },
    "interaction" : {
      "kind" : "relationship",
      "schema" : {
        "type" : "object",
        "properties" : {
          "summary" : {
            "type" : "string",
            "minLength" : 1,
            "maxLength" : 4000
          },
          "source" : {
            "type" : "string",
            "minLength" : 1,
            "maxLength" : 2000
          },
          "evidence_status" : {
            "type" : "string",
            "enum" : [ "reported", "attested" ]
          }
        },
        "required" : [ "summary", "source", "evidence_status" ],
        "additionalProperties" : false
      },
      "roles" : {
        "engagement" : {
          "min" : 1,
          "max" : 1,
          "types" : [ "salepiper/deal" ]
        },
        "participant" : {
          "min" : 0,
          "max" : 20,
          "types" : [ "salepiper/person", "salepiper/organization" ]
        }
      }
    },
    "next_action" : {
      "kind" : "relationship",
      "schema" : {
        "type" : "object",
        "properties" : {
          "title" : {
            "type" : "string",
            "minLength" : 1,
            "maxLength" : 160
          },
          "due_at" : {
            "type" : "string",
            "format" : "date-time",
            "minLength" : 1,
            "maxLength" : 40
          },
          "result" : {
            "type" : "string",
            "maxLength" : 4000
          }
        },
        "required" : [ "title", "due_at" ],
        "additionalProperties" : false
      },
      "roles" : {
        "engagement" : {
          "min" : 1,
          "max" : 1,
          "types" : [ "salepiper/deal" ]
        }
      },
      "lifecycle" : {
        "initial" : "open",
        "states" : [ "open", "complete" ]
      },
      "commands" : {
        "complete" : {
          "input" : {
            "type" : "object",
            "properties" : {
              "result" : {
                "type" : "string",
                "minLength" : 1,
                "maxLength" : 4000
              }
            },
            "required" : [ "result" ],
            "additionalProperties" : false
          },
          "from" : [ "open" ],
          "to" : "complete",
          "set_data" : {
            "result" : {
              "path" : [ "input", "result" ]
            }
          }
        }
      }
    }
  },
  "views" : {
    "open_deals" : {
      "type" : "deal",
      "where" : {
        "not" : {
          "any" : [ {
            "eq" : [ {
              "path" : [ "state" ]
            }, "won" ]
          }, {
            "eq" : [ {
              "path" : [ "state" ]
            }, "lost" ]
          } ]
        }
      },
      "fields" : [ "title", "amount", "currency" ]
    }
  }
}