{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "https://adsp.alberta.ca/common.v1.schema.json",
  "title": "Government of Alberta common definitions",
  "description": "JSON schema for Government of Alberta common definitions.",
  "definitions": {
    "personFullName": {
      "$comment": "The full name of a person including first, middle, and last names.",
      "type": "object",
      "properties": {
        "firstName": {
          "$ref": "https://adsp.alberta.ca/standard.v1.schema.json#/definitions/personName"
        },
        "middleName": {
          "$ref": "https://adsp.alberta.ca/standard.v1.schema.json#/definitions/personName"
        },
        "lastName": {
          "$ref": "https://adsp.alberta.ca/standard.v1.schema.json#/definitions/personName"
        }
      },
      "required": ["firstName", "lastName"],
      "errorMessage": {
        "properties": {
          "firstName": "Include period (.) if providing your initial",
          "middleName": "Include period (.) if providing your initial",
          "lastName": "Include period (.) if providing your initial"
        }
      }
    },
    "personFullNameAndDob": {
      "$comment": "Person full name and date of birth.",
      "type": "object",
      "properties": {
        "firstName": {
          "type": "string",
          "$ref": "https://adsp.alberta.ca/standard.v1.schema.json#/definitions/personName"
        },
        "middleName": {
          "type": "string",
          "$ref": "https://adsp.alberta.ca/standard.v1.schema.json#/definitions/personName"
        },
        "lastName": {
          "type": "string",
          "$ref": "https://adsp.alberta.ca/standard.v1.schema.json#/definitions/personName"
        },
        "dateOfBirth": {
          "type": "string",
          "format": "date"
        }
      },
      "required": ["firstName", "lastName", "dateOfBirth"],
      "errorMessage": {
        "properties": {
          "firstName": "Include period (.) if providing your initial",
          "middleName": "Include period (.) if providing your initial",
          "lastName": "Include period (.) if providing your initial"
        }
      }
    },
    "personDependent": {
      "$comment": "Dependent of a person of a specific type.",
      "title": "Dependent",
      "type": "object",
      "properties": {
        "firstName": {
          "$ref": "https://adsp.alberta.ca/standard.v1.schema.json#/definitions/personName"
        },
        "middleName": {
          "$ref": "https://adsp.alberta.ca/standard.v1.schema.json#/definitions/personName"
        },
        "lastName": {
          "$ref": "https://adsp.alberta.ca/standard.v1.schema.json#/definitions/personName"
        },
        "dateOfBirth": {
          "type": "string",
          "format": "date"
        },
        "dependentType": {
          "$ref": "#/definitions/personDependent/definitions/craDependentType"
        }
      },
      "required": ["firstName", "lastName", "dateOfBirth", "dependentType"],
      "errorMessage": {
        "properties": {
          "firstName": "Include period (.) if providing your initial",
          "middleName": "Include period (.) if providing your initial",
          "lastName": "Include period (.) if providing your initial"
        }
      },
      "definitions": {
        "craDependentType": {
          "type": "string",
          "enum": [
            "Parent or grandparent",
            "Child, grandchild, brother, or sister under 18 years of age",
            "Child, grandchild, brother, or sister 18 years of age or older with an impairment in physical or mental functions"
          ]
        }
      }
    },
    "personDependents": {
      "$comment": "Dependents of a person.",
      "title": "Dependents",
      "type": "array",
      "items": {
        "$ref": "#/definitions/personDependent"
      }
    },
    "postalAddressAlberta": {
      "$comment": "Postal address in Alberta.",
      "title": "Alberta postal address",
      "type": "object",
      "properties": {
        "addressLine1": {
          "$ref": "https://adsp.alberta.ca/standard.v1.schema.json#/definitions/postalAddress/properties/addressLine1"
        },
        "addressLine2": {
          "$ref": "https://adsp.alberta.ca/standard.v1.schema.json#/definitions/postalAddress/properties/addressLine2"
        },
        "municipality": {
          "$ref": "https://adsp.alberta.ca/standard.v1.schema.json#/definitions/postalAddress/properties/municipality"
        },
        "subdivisionCode": {
          "const": "AB"
        },
        "postalCode": {
          "$ref": "https://adsp.alberta.ca/standard.v1.schema.json#/definitions/postalCode/definitions/canadaPostalCode"
        },
        "country": {
          "const": "CA"
        }
      },
      "required": ["addressLine1", "municipality", "postalCode"],
      "errorMessage": {
        "properties": {
          "postalCode": "Must be in A0A 0A0 capital letters and numbers format"
        }
      }
    },
    "postalAddressCanada": {
      "$comment": "Postal address in Canada.",
      "title": "Canadian postal address",
      "type": "object",
      "properties": {
        "addressLine1": {
          "$ref": "https://adsp.alberta.ca/standard.v1.schema.json#/definitions/postalAddress/properties/addressLine1"
        },
        "addressLine2": {
          "$ref": "https://adsp.alberta.ca/standard.v1.schema.json#/definitions/postalAddress/properties/addressLine2"
        },
        "municipality": {
          "$ref": "https://adsp.alberta.ca/standard.v1.schema.json#/definitions/postalAddress/properties/municipality"
        },
        "subdivisionCode": {
          "title": "Province or territory",
          "description": "Two letter code for province or territory",
          "enum": ["AB", "BC", "MB", "NB", "NL", "NT", "NS", "NU", "ON", "PE", "QC", "SK", "YT"]
        },
        "postalCode": {
          "$ref": "https://adsp.alberta.ca/standard.v1.schema.json#/definitions/postalCode/definitions/canadaPostalCode"
        },
        "country": {
          "const": "CA"
        }
      },
      "required": ["addressLine1", "municipality", "subdivisionCode", "postalCode"],
      "errorMessage": {
        "properties": {
          "postalCode": "Must be in A0A 0A0 capital letters and numbers format"
        }
      }
    },
    "bankAccountNumber": {
      "$comment": "Bank account number for Canadian banks and credit unions with institution, branch, and account numbers.",
      "title": "Bank account number",
      "type": "object",
      "properties": {
        "institution": {
          "$comment": "Three digit institution number. Currently no valid codes start with 1, 4, or 9.",
          "title": "Institution number",
          "description": "000",
          "type": "string",
          "pattern": "^[02-35-8]\\d{2}$",
          "errorMessage": "Must be a valid three digit institution number."
        },
        "branch": {
          "$comment": "Five digit branch number.",
          "title": "Branch number",
          "description": "00000",
          "type": "string",
          "pattern": "^\\d{5}$",
          "errorMessage": "Must be a valid five digit branch number."
        },
        "account": {
          "$comment": "Institution specific account numbers typically seven or twelve digits and can include dashes and spaces.",
          "title": "Account number",
          "description": "0000000",
          "type": "string",
          "pattern": "^[\\d -]{6,14}$",
          "errorMessage": "Must be a valid account number which is typically 7 or 12 digits and can include dashes and spaces."
        }
      },
      "required": ["institution", "branch", "account"]
    },
    "bankAccountNumberString": {
      "$comment": "Bank account number for Canadian banks and credit unions as a single string value.",
      "title": "Bank account number",
      "description": "000-00000 0000000",
      "type": "string",
      "pattern": "^[02-35-8]\\d{2}-\\d{5} [\\d -]{6,14}$",
      "errorMessage": "Must be [3 digit institution #]-[5 digit branch #] [account # often 7 or 12 digits]"
    },
    "socialInsuranceNumber": {
      "$comment": "Canadian social insurance number.",
      "title": "Social insurance number",
      "description": "000 000 000",
      "type": "string",
      "pattern": "^\\d{3} \\d{3} \\d{3}$",
      "errorMessage": "Must be three groups of three digits."
    },
    "email": {
      "$comment": "Standard email address",
      "title": "Email address",
      "type": "string",
      "format": "email",
      "maxLength": 100,
      "description": "a.n.other@example.com",
      "errorMessage": {
        "format": "Must be in a format like a.n.other@example.com",
        "maxLength": "Must be less than 100 characters."
      }
    },
    "phoneNumber": {
      "$comment": "North American phone number.",
      "title": "Phone number",
      "description": "(000) 000-0000",
      "type": "string",
      "pattern": "^\\(?\\d{3}\\)?[- ]?\\d{3}[- ]?\\d{4}$",
      "errorMessage": "Must be a valid 10-digit phone number in format (000) 000-0000"
    },
    "phoneNumberWithType": {
      "$comment": "Phone number with type classification.",
      "title": "Phone number",
      "type": "object",
      "properties": {
        "number": {
          "$ref": "#/definitions/phoneNumber"
        },
        "type": {
          "type": "string",
          "enum": ["Mobile", "Landline"],
          "title": "Phone type"
        }
      },
      "required": ["number", "type"]
    },
    "contactInformation": {
      "type": "object",
      "properties": {
        "email": {
          "$ref": "#/definitions/email"
        },
        "phone": {
          "$ref": "#/definitions/phoneNumber"
        },
        "preferredContactMethod": {
          "type": "string",
          "enum": ["Email", "Phone"]
        }
      },
      "anyOf": [{ "required": ["email"] }, { "required": ["phone"] }]
    }
  }
}
