{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://kaikei.keydrop.net/schema/0.1/periods.schema.json",
  "title": "会計期間",
  "description": "periods.json（03-periods.md）。期間が連続し重ならないこと、1 年を超えないことは Validator が検証する",
  "type": "object",
  "required": [
    "periods"
  ],
  "properties": {
    "periods": {
      "type": "array",
      "minItems": 1,
      "items": {
        "type": "object",
        "required": [
          "id",
          "start",
          "end",
          "status"
        ],
        "properties": {
          "id": {
            "$ref": "common.schema.json#/$defs/identifier"
          },
          "start": {
            "$ref": "common.schema.json#/$defs/date"
          },
          "end": {
            "$ref": "common.schema.json#/$defs/date"
          },
          "status": {
            "enum": [
              "open",
              "closing",
              "closed"
            ]
          },
          "lockedThrough": {
            "$ref": "common.schema.json#/$defs/date"
          },
          "interimEnd": {
            "$ref": "common.schema.json#/$defs/date",
            "description": "中間決算日（任意）"
          },
          "note": {
            "type": "string"
          },
          "extensions": {
            "$ref": "common.schema.json#/$defs/extensions"
          },
          "interimPayments": {
            "type": "array",
            "description": "消費税の中間納付（申告書の計算に使う）",
            "items": {
              "type": "object",
              "required": [
                "kind",
                "amount"
              ],
              "properties": {
                "kind": {
                  "enum": [
                    "consumption_tax",
                    "local_consumption_tax"
                  ]
                },
                "amount": {
                  "$ref": "common.schema.json#/$defs/amount"
                },
                "dueDate": {
                  "$ref": "common.schema.json#/$defs/date"
                },
                "entry": {
                  "$ref": "common.schema.json#/$defs/ulid"
                }
              },
              "additionalProperties": false
            }
          }
        },
        "additionalProperties": false
      }
    },
    "fiscalYearEndRule": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "validFrom",
          "month",
          "day"
        ],
        "properties": {
          "validFrom": {
            "$ref": "common.schema.json#/$defs/date"
          },
          "month": {
            "type": "integer",
            "minimum": 1,
            "maximum": 12
          },
          "day": {
            "oneOf": [
              {
                "const": "end"
              },
              {
                "type": "integer",
                "minimum": 1,
                "maximum": 28
              }
            ]
          },
          "extensions": {
            "$ref": "common.schema.json#/$defs/extensions"
          }
        },
        "additionalProperties": false
      }
    },
    "lockHistory": {
      "type": "array",
      "items": {
        "type": "object",
        "required": [
          "at",
          "action"
        ],
        "properties": {
          "at": {
            "$ref": "common.schema.json#/$defs/datetime"
          },
          "action": {
            "enum": [
              "lock",
              "unlock"
            ]
          },
          "from": {
            "$ref": "common.schema.json#/$defs/date"
          },
          "to": {
            "$ref": "common.schema.json#/$defs/date"
          },
          "reason": {
            "type": "string"
          },
          "extensions": {
            "$ref": "common.schema.json#/$defs/extensions"
          }
        },
        "additionalProperties": false
      }
    },
    "extensions": {
      "$ref": "common.schema.json#/$defs/extensions"
    }
  },
  "additionalProperties": false
}
