{
  "definitions": {},
  "$schema": "http://json-schema.org/draft-07/schema#",
  "$id": "http://www.canada.ca/en/fcpf-json-schema.json",
  "type": "object",
  "title": "FCAC Financial Consumer Protection Framework - Bulk Schema Definition File",
  "required": [
    "complaints"
  ],
  "additionalProperties": false,
  "properties": {
    "complaints": {
      "$id": "#/complaints",
      "type": "object",
      "title": "A collection of complaint objects that relate to the FCPF.",
      "required": [
        "complaint"
      ],
      "additionalProperties": false,
      "properties": {
        "complaint": {
          "uniqueItems": true,
          "$id": "#/complaints/complaint",
          "type": "array",
          "title": "The collection of complaints.",
          "items": {
            "$id": "#/complaints/complaint/record",
            "type": "object",
            "title": "The definition of an individual complaint record.",
            "required": [
              "record-id",
              "anonymous",
              "channel",
              "description",
              "resolution-description",
              "compensation-description",
              "confirmation-provided",
              "attachment-reference",
              "status",
              "received-date",
              "classifications"
            ],
            "allOf": [
              {
                "if": {
                  "properties": {
                    "anonymous": { "const": false }
                  }
                },
                "then": {
                  "required": [
                    "complainant-first-name",
                    "complainant-last-name",
                    "complainant-postal-code",
                    "complainant-same-customer",
                    "customer-type"
                  ]
                }
              },
              {
                "if": {
                  "properties": {
                    "anonymous": { "const": false },
                    "complainant-same-customer": { "const": false },
                    "customer-type": { "const": "Personal" }
                  }
                },
                "then": {
                  "required": [
                    "customer-first-name",
                    "customer-last-name"
                  ]
                }
              },
              {
                "if": {
                  "properties": {
                    "anonymous": { "const": false },
                    "complainant-same-customer": { "const": false },
                    "customer-type": { "const": "Commercial" }
                  }
                },
                "then": {
                  "required": [ "customer-company" ]
                }
              },
              {
                "if": {
                  "properties": {
                    "status": { "const": "Reopened" }
                  }
                },
                "then": {
                  "required": [ "reopened-date" ]
                }
              },
              {
                "if": {
                  "properties": {
                    "status": { "const": "Resolved" }
                  }
                },
                "then": {
                  "required": [ "resolved-date" ]
                }
              },
              {
                "if": {
                  "properties": {
                    "status": { "const": "Closed" }
                  }
                },
                "then": {
                  "required": [ "closed-date" ]
                }
              }
            ],
            "additionalProperties": false,
            "properties": {
              "record-id": {
                "$id": "#/complaints/complaint/record/record-id",
                "type": "string",
                "title": "A unique identifier, used by the institution to identify the complaint in their source platform.",
                "default": "",
                "maxLength": 150,
                "examples": [
                  "FCAC-12_345 Y"
                ],
                "pattern": "^[a-zA-Z0-9 _-]+$"
              },
              "classifications": {
                "$id": "#/complaints/complaint/record/classifications",
                "type": "object",
                "title": "The classifications associated with the complaint.",
                "required": [
                  "classification"
                ],
                "additionalProperties": false,
                "properties": {
                  "classification": {
                    "$id": "#/complaints/complaint/record/classification",
                    "type": "array",
                    "uniqueItems": true,
                    "minItems": 1,
                    "title": "The classification definition, see validation rule 1.1",
                    "items": {
                      "$id": "#/complaints/complaint/record/classification/record",
                      "type": "object",
                      "title": "classification Schema Structure",
                      "required": [
                        "primary-product-service",
                        "secondary-product-service"
                      ],
                      "additionalProperties": false,
                      "properties": {
                        "primary-product-service": {
                          "$id": "#/complaints/complaint/record/classification/primary-product-service",
                          "type": "string",
                          "title": "The Primary Product/Service Classification.",
                          "enum": [ "Account", "Credit card", "Debit card", "HELOC", "Insurance", "Investment", "Line of credit", "Loan", "Mortgage", "Prepaid card", "Other" ],
                          "examples": [
                            "Mortgage"
                          ]
                        },
                        "secondary-product-service": {
                          "$id": "#/complaints/complaint/record/classification/secondary-product-service",
                          "type": "string",
                          "title": "The Secondary Product/Service Classification.",
                          "enum": [ "Agreement", "Alerts", "Balance", "Cancellation", "Closure", "Collections", "Complaint handling", "Credit limit", "Creditor insurance", "Estate", "Fees / Charges", "Financial advisor services", "Interest", "Internet banking / Services", "Mobile phone banking / Services", "Opening", "Overdraft", "Payment", "Power of attorney", "Renewal", "Safety deposit box", "Statement", "Telephone banking / Services", "Teller services", "Transaction", "Transfer", "Other" ],
                          "examples": [
                            "Agreement"
                          ]
                        }
                      }
                    }
                  }
                }
              },
              "channel": {
                "$id": "#/complaints/complaint/record/channel",
                "type": "string",
                "title": "Media Channel the complaint originated from.",
                "enum": [ "Social", "Voice", "Fax", "Web", "In-Person", "Email", "Letter", "Chat" ],
                "examples": [
                  "Social"
                ]
              },
              "description": {
                "$id": "#/complaints/complaint/record/description",
                "type": "string",
                "title": "Description of the Complaint",
                "default": "",
                "maxLength": 2500,
                "examples": [
                  "This is my complaint"
                ]
              },
              "anonymous": {
                "$id": "#/complaints/complaint/record/anonymous",
                "type": "boolean",
                "title": "Identifies whether the complaint was logged anonymously",
                "default": "false",
                "examples": [
                  "false"
                ]
              },
              "complainant-first-name": {
                "$id": "#/complaints/complaint/record/complainant-first-name",
                "type": "string",
                "title": "The First Name of the Complainant",
                "maxLength": 150,
                "examples": [
                  "Jack"
                ],
                "pattern": "^[A-Za-z\u00C0-\u017F ,.'-_&]+$$"
              },
              "complainant-last-name": {
                "$id": "#/complaints/complaint/record/complainant-last-name",
                "type": "string",
                "title": "The Last Name of the Complainant",
                "maxLength": 150,
                "examples": [
                  "Wilson"
                ],
                "pattern": "^[A-Za-z\u00C0-\u017F ,.'-_&]+$$"
              },
              "complainant-postal-code": {
                "$id": "#/complaints/complaint/record/complainant-postal-code",
                "type": "string",
                "title": "The Postal Code of the Complainant",
                "default": "",
                "maxLength": 15,
                "examples": [
                  "H0H 0H0"
                ],
                "anyOf": [
                  { "pattern": "^([a-zA-Z]\\d[a-zA-z]( )?\\d[a-zA-Z]\\d)$" },
                  { "const": "International" }
                ]
              },
              "complainant-same-customer": {
                "$id": "#/complaints/complaint/record/complainant-same-customer",
                "type": "boolean",
                "title": "Is the complaintant the same as the customer",
                "default": "false",
                "examples": [
                  "false"
                ]
              },
              "customer-type": {
                "$id": "#/complaints/complaint/record/customer-type",
                "type": "string",
                "title": "The type of customer",
                "enum": [ "Personal", "Commercial" ],
                "examples": [
                  "Personal"
                ]
              },
              "customer-first-name": {
                "$id": "#/complaints/complaint/record/customer-first-name",
                "type": "string",
                "title": "The First Name of the customer",
                "maxLength": 150,
                "examples": [
                  "Jack"
                ],
                "pattern": "^[A-Za-z\u00C0-\u017F ,.'-_&]+$$"
              },
              "customer-last-name": {
                "$id": "#/complaints/complaint/customer-last-name",
                "type": "string",
                "title": "The Last Name of the customer",
                "default": "",
                "maxLength": 150,
                "examples": [
                  "Wilson"
                ],
                "pattern": "^[A-Za-z\u00C0-\u017F ,.'-_&]+$$"
              },
              "customer-company": {
                "$id": "#/complaints/complaint/record/customer-company",
                "type": "string",
                "title": "The Company of the customer",
                "default": "",
                "maxLength": 150,
                "examples": [
                  "XYZ Inc"
                ],
                "pattern": "^[A-Za-z\u00C0-\u017F ,.'-_&#!]+$$"
              },
              "resolution-description": {
                "$id": "#/complaints/complaint/record/resolution-description",
                "type": "string",
                "title": "A descriptive resolution of the complaint.",
                "default": "",
                "maxLength": 3000,
                "examples": [
                  "This is my resolution."
                ]
              },
              "compensation-description": {
                "$id": "#/complaints/complaint/record/compensation-description",
                "type": "string",
                "title": "A descriptive compensation of the compalaint.",
                "default": "",
                "maxLength": 3000,
                "examples": [
                  "This was the compensation."
                ]
              },
              "confirmation-provided": {
                "$id": "#/complaints/complaint/record/confirmation-provided",
                "type": "boolean",
                "title": "Confirmation that the complaint has been handled.",
                "default": "true",
                "examples": [
                  "false"
                ]
              },
              "attachment-reference": {
                "$id": "#/complaints/complaint/record/attachment-reference",
                "type": "string",
                "enum": [ "Original in Writing", "Call Recording", "Call Transcript", "Details of the Complaint (Not Recorded)" ],
                "title": "A reference to the type of collatoral information the complaint was initially logged with.",
                "default": "New",
                "examples": [
                  "Call Recording"
                ]
              },
              "status": {
                "$id": "#/complaints/complaint/record/status",
                "type": "string",
                "enum": [ "Ongoing", "Reopened", "Resolved", "Closed" ],
                "title": "The Status of the complaint.",
                "default": "Ongoing",
                "examples": [
                  "Ongoing"
                ]
              },
              "resolved-date": {
                "$id": "#/complaints/complaint/record/resolved-date",
                "type": "string",
                "title": "The resolved date of the complaint.",
                "description": "Date-time Format must be in yyyy-MM-dd.",
                "format": "date",
                "examples": [
                  "2022-01-01"
                ]
              },
              "received-date": {
                "$id": "#/complaints/complaint/record/received-date",
                "type": "string",
                "title": "The received date of the complaint.",
                "description": "Date-time Format must be in yyyy-MM-dd.",
                "format": "date",
                "examples": [
                  "2022-01-01"
                ]
              },
              "reopened-date": {
                "$id": "#/complaints/complaint/record/reopened-date",
                "type": "string",
                "title": "The reopened date of the complaint.",
                "description": "Date-time Format must be in yyyy-MM-dd.",
                "format": "date",
                "examples": [
                  "2022-01-01"
                ]
              },
              "closed-date": {
                "$id": "#/complaints/complaint/record/closed-date",
                "type": "string",
                "title": "The closed date of the complaint.",
                "description": "Date-time Format must be in yyyy-MM-dd.",
                "format": "date",
                "examples": [
                  "2022-01-01"
                ]
              }
            }
          }
        }
      }
    }
  }
}
