{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "title": "YearEndCloseReadinessRequest",
  "type": "object",
  "additionalProperties": false,
  "required": [
    "period",
    "account_manifest",
    "exception_counts",
    "checklist_policy"
  ],
  "properties": {
    "period": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "start",
        "end",
        "basis"
      ],
      "properties": {
        "start": {
          "type": "string",
          "format": "date"
        },
        "end": {
          "type": "string",
          "format": "date"
        },
        "basis": {
          "type": "string",
          "enum": [
            "cash",
            "accrual"
          ]
        }
      }
    },
    "account_manifest": {
      "type": "array",
      "minItems": 1,
      "maxItems": 500,
      "items": {
        "type": "object",
        "additionalProperties": false,
        "required": [
          "account_id",
          "account_type",
          "last_reconciled_date",
          "statement_present"
        ],
        "properties": {
          "account_id": {
            "type": "string",
            "pattern": "^a_[0-9a-f]{16}$"
          },
          "account_type": {
            "type": "string",
            "enum": [
              "cash",
              "savings",
              "credit_card",
              "loan",
              "receivable",
              "payable",
              "inventory",
              "fixed_asset",
              "payroll",
              "tax",
              "equity",
              "other"
            ]
          },
          "last_reconciled_date": {
            "oneOf": [
              {
                "type": "string",
                "format": "date"
              },
              {
                "type": "null"
              }
            ]
          },
          "statement_present": {
            "type": "boolean"
          },
          "declared_balance_cents": {
            "type": "integer",
            "minimum": -9000000000000000,
            "maximum": 9000000000000000
          },
          "close_status": {
            "type": "string",
            "enum": [
              "not_started",
              "in_progress",
              "review",
              "complete",
              "not_applicable",
              "unknown"
            ]
          }
        }
      }
    },
    "exception_counts": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "unreconciled_items",
        "unclassified_transactions",
        "missing_documents",
        "duplicate_entries",
        "open_adjustments",
        "unmatched_payments",
        "other_review_items"
      ],
      "properties": {
        "unreconciled_items": {
          "type": "integer",
          "minimum": 0,
          "maximum": 1000000
        },
        "unclassified_transactions": {
          "type": "integer",
          "minimum": 0,
          "maximum": 1000000
        },
        "missing_documents": {
          "type": "integer",
          "minimum": 0,
          "maximum": 1000000
        },
        "duplicate_entries": {
          "type": "integer",
          "minimum": 0,
          "maximum": 1000000
        },
        "open_adjustments": {
          "type": "integer",
          "minimum": 0,
          "maximum": 1000000
        },
        "unmatched_payments": {
          "type": "integer",
          "minimum": 0,
          "maximum": 1000000
        },
        "other_review_items": {
          "type": "integer",
          "minimum": 0,
          "maximum": 1000000
        }
      }
    },
    "trial_balance_totals": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "debit_cents",
        "credit_cents"
      ],
      "properties": {
        "debit_cents": {
          "type": "integer",
          "minimum": -9000000000000000,
          "maximum": 9000000000000000
        },
        "credit_cents": {
          "type": "integer",
          "minimum": -9000000000000000,
          "maximum": 9000000000000000
        }
      }
    },
    "inventory_count_status": {
      "type": "string",
      "enum": [
        "complete",
        "in_progress",
        "review_required",
        "not_applicable",
        "unknown"
      ]
    },
    "fixed_asset_review_status": {
      "type": "string",
      "enum": [
        "complete",
        "in_progress",
        "review_required",
        "not_applicable",
        "unknown"
      ]
    },
    "payroll_reconciliation_status": {
      "type": "string",
      "enum": [
        "complete",
        "in_progress",
        "review_required",
        "not_applicable",
        "unknown"
      ]
    },
    "checklist_policy": {
      "type": "object",
      "additionalProperties": false,
      "required": [
        "policy_id",
        "version",
        "checks"
      ],
      "properties": {
        "policy_id": {
          "type": "string",
          "pattern": "^p_[0-9a-z][0-9a-z_.-]{2,63}$"
        },
        "version": {
          "type": "string",
          "pattern": "^[0-9]+\\.[0-9]+(?:\\.[0-9]+)?$"
        },
        "checks": {
          "type": "array",
          "minItems": 1,
          "maxItems": 1000,
          "items": {
            "oneOf": [
              {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "check_id",
                  "mode",
                  "predicate",
                  "account_types"
                ],
                "properties": {
                  "check_id": {
                    "type": "string",
                    "pattern": "^[a-z][a-z0-9_]{1,47}$"
                  },
                  "mode": {
                    "type": "string",
                    "enum": [
                      "required",
                      "review"
                    ]
                  },
                  "dependencies": {
                    "type": "array",
                    "maxItems": 32,
                    "uniqueItems": true,
                    "items": {
                      "type": "string",
                      "pattern": "^[a-z][a-z0-9_]{1,47}$"
                    }
                  },
                  "predicate": {
                    "const": "STATEMENT_PRESENT"
                  },
                  "account_types": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 12,
                    "uniqueItems": true,
                    "items": {
                      "type": "string",
                      "enum": [
                        "cash",
                        "savings",
                        "credit_card",
                        "loan",
                        "receivable",
                        "payable",
                        "inventory",
                        "fixed_asset",
                        "payroll",
                        "tax",
                        "equity",
                        "other"
                      ]
                    }
                  }
                }
              },
              {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "check_id",
                  "mode",
                  "predicate",
                  "account_types"
                ],
                "properties": {
                  "check_id": {
                    "type": "string",
                    "pattern": "^[a-z][a-z0-9_]{1,47}$"
                  },
                  "mode": {
                    "type": "string",
                    "enum": [
                      "required",
                      "review"
                    ]
                  },
                  "dependencies": {
                    "type": "array",
                    "maxItems": 32,
                    "uniqueItems": true,
                    "items": {
                      "type": "string",
                      "pattern": "^[a-z][a-z0-9_]{1,47}$"
                    }
                  },
                  "predicate": {
                    "const": "BALANCE_PRESENT"
                  },
                  "account_types": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 12,
                    "uniqueItems": true,
                    "items": {
                      "type": "string",
                      "enum": [
                        "cash",
                        "savings",
                        "credit_card",
                        "loan",
                        "receivable",
                        "payable",
                        "inventory",
                        "fixed_asset",
                        "payroll",
                        "tax",
                        "equity",
                        "other"
                      ]
                    }
                  }
                }
              },
              {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "check_id",
                  "mode",
                  "predicate",
                  "account_types"
                ],
                "properties": {
                  "check_id": {
                    "type": "string",
                    "pattern": "^[a-z][a-z0-9_]{1,47}$"
                  },
                  "mode": {
                    "type": "string",
                    "enum": [
                      "required",
                      "review"
                    ]
                  },
                  "dependencies": {
                    "type": "array",
                    "maxItems": 32,
                    "uniqueItems": true,
                    "items": {
                      "type": "string",
                      "pattern": "^[a-z][a-z0-9_]{1,47}$"
                    }
                  },
                  "predicate": {
                    "const": "RECONCILED_ON_OR_AFTER"
                  },
                  "account_types": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 12,
                    "uniqueItems": true,
                    "items": {
                      "type": "string",
                      "enum": [
                        "cash",
                        "savings",
                        "credit_card",
                        "loan",
                        "receivable",
                        "payable",
                        "inventory",
                        "fixed_asset",
                        "payroll",
                        "tax",
                        "equity",
                        "other"
                      ]
                    }
                  },
                  "cutoff_date": {
                    "type": "string",
                    "format": "date"
                  },
                  "max_days_before_period_end": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 366
                  }
                },
                "oneOf": [
                  {
                    "required": [
                      "cutoff_date"
                    ],
                    "not": {
                      "required": [
                        "max_days_before_period_end"
                      ]
                    }
                  },
                  {
                    "required": [
                      "max_days_before_period_end"
                    ],
                    "not": {
                      "required": [
                        "cutoff_date"
                      ]
                    }
                  }
                ]
              },
              {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "check_id",
                  "mode",
                  "predicate",
                  "category",
                  "max_count"
                ],
                "properties": {
                  "check_id": {
                    "type": "string",
                    "pattern": "^[a-z][a-z0-9_]{1,47}$"
                  },
                  "mode": {
                    "type": "string",
                    "enum": [
                      "required",
                      "review"
                    ]
                  },
                  "dependencies": {
                    "type": "array",
                    "maxItems": 32,
                    "uniqueItems": true,
                    "items": {
                      "type": "string",
                      "pattern": "^[a-z][a-z0-9_]{1,47}$"
                    }
                  },
                  "predicate": {
                    "const": "EXCEPTION_COUNT_AT_MOST"
                  },
                  "category": {
                    "type": "string",
                    "enum": [
                      "unreconciled_items",
                      "unclassified_transactions",
                      "missing_documents",
                      "duplicate_entries",
                      "open_adjustments",
                      "unmatched_payments",
                      "other_review_items"
                    ]
                  },
                  "max_count": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 1000000
                  }
                }
              },
              {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "check_id",
                  "mode",
                  "predicate",
                  "fact",
                  "allowed_statuses"
                ],
                "properties": {
                  "check_id": {
                    "type": "string",
                    "pattern": "^[a-z][a-z0-9_]{1,47}$"
                  },
                  "mode": {
                    "type": "string",
                    "enum": [
                      "required",
                      "review"
                    ]
                  },
                  "dependencies": {
                    "type": "array",
                    "maxItems": 32,
                    "uniqueItems": true,
                    "items": {
                      "type": "string",
                      "pattern": "^[a-z][a-z0-9_]{1,47}$"
                    }
                  },
                  "predicate": {
                    "const": "STATUS_IN"
                  },
                  "fact": {
                    "type": "string",
                    "enum": [
                      "inventory_count_status",
                      "fixed_asset_review_status",
                      "payroll_reconciliation_status"
                    ]
                  },
                  "allowed_statuses": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 5,
                    "uniqueItems": true,
                    "items": {
                      "type": "string",
                      "enum": [
                        "complete",
                        "in_progress",
                        "review_required",
                        "not_applicable",
                        "unknown"
                      ]
                    }
                  }
                }
              },
              {
                "type": "object",
                "additionalProperties": false,
                "required": [
                  "check_id",
                  "mode",
                  "predicate",
                  "account_types",
                  "min_count"
                ],
                "properties": {
                  "check_id": {
                    "type": "string",
                    "pattern": "^[a-z][a-z0-9_]{1,47}$"
                  },
                  "mode": {
                    "type": "string",
                    "enum": [
                      "required",
                      "review"
                    ]
                  },
                  "dependencies": {
                    "type": "array",
                    "maxItems": 32,
                    "uniqueItems": true,
                    "items": {
                      "type": "string",
                      "pattern": "^[a-z][a-z0-9_]{1,47}$"
                    }
                  },
                  "predicate": {
                    "const": "ACCOUNT_COUNT_AT_LEAST"
                  },
                  "account_types": {
                    "type": "array",
                    "minItems": 1,
                    "maxItems": 12,
                    "uniqueItems": true,
                    "items": {
                      "type": "string",
                      "enum": [
                        "cash",
                        "savings",
                        "credit_card",
                        "loan",
                        "receivable",
                        "payable",
                        "inventory",
                        "fixed_asset",
                        "payroll",
                        "tax",
                        "equity",
                        "other"
                      ]
                    }
                  },
                  "min_count": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 500
                  }
                }
              }
            ]
          }
        }
      }
    }
  }
}
