####
#### Use kwalify and this schema to validate the config files.
####
#### Example hash generation:
####    echo -n "foo.bar@bib.edu" | md5sum
####
#### Examples:
####    kwalify -f ./metadata/users.schema.yaml ./metadata/users.yaml
####    kwalify -f ./metadata/users.schema.yaml ./metadata/users.yaml | grep INVALID; test $? -ne 0
####
type: seq
sequence:
  - type: map
    mapping:
      "uri":
        type: str
        required: true
        unique: true
        pattern: /^((ht|f)tp(s?)\:\/\/\w[\/\.\-\:\w]+)|(GOC\:[\w\_]+)$/
      "xref":
        type: str
        required: false
        unique: true
        pattern: /^\w+:\w+$/
      "nickname":
        type: str
        required: true
        unique: true
      "authorizations":
        type: map
        required: false
        mapping:
          ## Legacy "noctua-go".
          "noctua-go":
            type: map
            required: false
            mapping:
              "allow-edit":
                type: bool
                required: false
              "allow-admin":
                type: bool
                required: false
              "temporary-user":
                type: bool
                required: false
              "model-lock":
                type: seq
                required: false
                sequence:
                  - type: str
          ## Template for further additions.
          "noctua":
            type: map
            required: false
            mapping:
              "go": &noctua_auth_template
                type: map
                required: false
                mapping:
                  "allow-edit":
                    type: bool
                    required: true
                  "allow-admin":
                    type: bool
                    required: false
                  "temporary-user":
                    type: bool
                    required: false
                  "model-lock":
                    type: seq
                    required: false
                    sequence:
                      - type: str
              "monarch": *noctua_auth_template
              "open": *noctua_auth_template
      "comment":
        type: str
        required: false
      "organization":
        type: str
        required: false
      "groups":
        type: seq
        required: false
        sequence:
          - type: str
            ## Pattern lookahead to prevent trailing slashes.
            pattern: /^(http(s?)\:\/\/\w[\/\.\-\:\w]+)(?<!\/)$/
      "previous-groups":
        type: seq
        required: false
        sequence:
          - type: str
            ## Pattern lookahead to prevent trailing slashes.
            pattern: /^(http(s?)\:\/\/\w[\/\.\-\:\w]+)(?<!\/)$/
      "accounts":
        type: map
        required: false
        mapping:
          "google-plus":
            type: str
            required: false
            unique: true
          "github":
            type: str
            required: false
            unique: true
          "orcid":
            type: str
            required: false
            unique: true
