{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://evaluation.keydrop.net/schema/0.3/bundle.schema.json",
  "title": "OES の JSON の形（oes-bundle）",
  "description": "表の行の形を検証する。表をまたぐ業務ルールは検証ツールが確かめる（spec/09-rules.md）。知らない列は許す（警告は検証ツールが出す）",
  "type": "object",
  "required": [
    "format",
    "specVersion",
    "fileType",
    "tables"
  ],
  "properties": {
    "$schema": {
      "type": "string"
    },
    "format": {
      "const": "oes-bundle"
    },
    "specVersion": {
      "type": "string",
      "pattern": "^0\\.[0-9]+\\.[0-9]+(-[0-9A-Za-z.-]+)?$"
    },
    "fileType": {
      "enum": [
        "master",
        "distribution"
      ]
    },
    "fileId": {
      "type": "string"
    },
    "masterFileId": {
      "type": "string"
    },
    "distributionId": {
      "$ref": "common.schema.json#/$defs/ulid"
    },
    "generator": {
      "type": "object",
      "required": [
        "name"
      ],
      "properties": {
        "name": {
          "type": "string"
        },
        "version": {
          "type": "string"
        }
      }
    },
    "createdAt": {
      "$ref": "common.schema.json#/$defs/dateTime"
    },
    "locale": {
      "description": "シートの見出し・列挙の表示名の言語（BCP 47。spec/01-basics.md の「言語」。0.3）",
      "type": "string",
      "pattern": "^[A-Za-z]{2,3}(-[A-Za-z0-9]{2,8})*$"
    },
    "tables": {
      "type": "object",
      "properties": {
        "settings": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/keyValue"
          }
        },
        "guide": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/keyValue"
          }
        },
        "departments": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/department"
          }
        },
        "categories": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/category"
          }
        },
        "grades": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/grade"
          }
        },
        "gradeWeights": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/gradeWeight"
          }
        },
        "employees": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/employee"
          }
        },
        "transfers": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/transfer"
          }
        },
        "items": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/item"
          }
        },
        "itemCriteria": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/itemCriterion"
          }
        },
        "periods": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/period"
          }
        },
        "ratings": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/rating"
          }
        },
        "assignments": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/assignment"
          }
        },
        "goals": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/goal"
          }
        },
        "details": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/detail"
          }
        },
        "results": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/result"
          }
        },
        "interviews": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/interview"
          }
        },
        "history": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/historyRow"
          }
        },
        "submissions": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/submission"
          }
        },
        "processSteps": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/processStep"
          }
        },
        "stepStates": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/stepState"
          }
        },
        "goalScale": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/goalScaleRow"
          }
        },
        "goalDifficulties": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/goalDifficulty"
          }
        }
      },
      "patternProperties": {
        "^x-": {
          "type": "array",
          "items": {
            "type": "object"
          }
        }
      }
    },
    "extensions": {
      "$ref": "common.schema.json#/$defs/extensions"
    }
  },
  "$defs": {
    "keyValue": {
      "type": "object",
      "required": [
        "key"
      ],
      "properties": {
        "key": {
          "type": "string",
          "minLength": 1
        },
        "value": {
          "type": [
            "string",
            "number",
            "boolean",
            "array"
          ]
        },
        "note": {
          "type": "string"
        }
      }
    },
    "department": {
      "type": "object",
      "required": [
        "code",
        "name"
      ],
      "properties": {
        "code": {
          "$ref": "common.schema.json#/$defs/code"
        },
        "name": {
          "type": "string",
          "minLength": 1
        },
        "parentCode": {
          "$ref": "common.schema.json#/$defs/code"
        },
        "headEmployeeNo": {
          "$ref": "common.schema.json#/$defs/code"
        },
        "order": {
          "type": "number"
        },
        "active": {
          "type": "boolean"
        }
      }
    },
    "category": {
      "type": "object",
      "required": [
        "code",
        "name",
        "kind"
      ],
      "properties": {
        "code": {
          "$ref": "common.schema.json#/$defs/code"
        },
        "name": {
          "type": "string",
          "minLength": 1
        },
        "kind": {
          "enum": [
            "goal",
            "item"
          ]
        },
        "order": {
          "type": "number"
        }
      }
    },
    "grade": {
      "type": "object",
      "required": [
        "code",
        "name"
      ],
      "properties": {
        "code": {
          "$ref": "common.schema.json#/$defs/code"
        },
        "name": {
          "type": "string",
          "minLength": 1
        },
        "salaryMin": {
          "type": "number",
          "minimum": 0
        },
        "salaryMax": {
          "type": "number",
          "minimum": 0
        },
        "order": {
          "type": "number"
        },
        "active": {
          "type": "boolean"
        }
      }
    },
    "gradeWeight": {
      "type": "object",
      "required": [
        "gradeCode",
        "categoryCode",
        "weight"
      ],
      "properties": {
        "gradeCode": {
          "$ref": "common.schema.json#/$defs/code"
        },
        "categoryCode": {
          "$ref": "common.schema.json#/$defs/code"
        },
        "weight": {
          "type": "number",
          "minimum": 0
        }
      }
    },
    "employee": {
      "type": "object",
      "required": [
        "employeeNo",
        "name"
      ],
      "properties": {
        "employeeNo": {
          "$ref": "common.schema.json#/$defs/code"
        },
        "name": {
          "type": "string",
          "minLength": 1
        },
        "kana": {
          "type": "string"
        },
        "email": {
          "type": "string",
          "format": "email"
        },
        "departmentCode": {
          "$ref": "common.schema.json#/$defs/code"
        },
        "gradeCode": {
          "$ref": "common.schema.json#/$defs/code"
        },
        "title": {
          "type": "string"
        },
        "employmentType": {
          "type": "string"
        },
        "hiredOn": {
          "$ref": "common.schema.json#/$defs/date"
        },
        "firstEvaluatorNo": {
          "$ref": "common.schema.json#/$defs/code"
        },
        "secondEvaluatorNo": {
          "$ref": "common.schema.json#/$defs/code"
        },
        "evaluationTarget": {
          "type": "boolean"
        },
        "status": {
          "enum": [
            "active",
            "leave",
            "retired"
          ]
        },
        "retiredOn": {
          "$ref": "common.schema.json#/$defs/date"
        },
        "photoFileId": {
          "type": "string"
        }
      }
    },
    "transfer": {
      "type": "object",
      "required": [
        "employeeNo",
        "effectiveOn"
      ],
      "properties": {
        "employeeNo": {
          "$ref": "common.schema.json#/$defs/code"
        },
        "effectiveOn": {
          "$ref": "common.schema.json#/$defs/date"
        },
        "departmentCode": {
          "$ref": "common.schema.json#/$defs/code"
        },
        "gradeCode": {
          "$ref": "common.schema.json#/$defs/code"
        },
        "title": {
          "type": "string"
        },
        "note": {
          "type": "string"
        }
      }
    },
    "item": {
      "type": "object",
      "required": [
        "code",
        "categoryCode",
        "name"
      ],
      "properties": {
        "code": {
          "$ref": "common.schema.json#/$defs/code"
        },
        "categoryCode": {
          "$ref": "common.schema.json#/$defs/code"
        },
        "name": {
          "type": "string",
          "minLength": 1
        },
        "description": {
          "type": "string"
        },
        "gradeCodes": {
          "$ref": "common.schema.json#/$defs/codeList"
        },
        "employmentTypes": {
          "$ref": "common.schema.json#/$defs/stringList"
        },
        "weight": {
          "$ref": "common.schema.json#/$defs/positiveWeight"
        },
        "order": {
          "type": "number"
        },
        "active": {
          "type": "boolean"
        }
      }
    },
    "itemCriterion": {
      "type": "object",
      "required": [
        "itemCode",
        "score",
        "text"
      ],
      "properties": {
        "itemCode": {
          "$ref": "common.schema.json#/$defs/code"
        },
        "score": {
          "$ref": "common.schema.json#/$defs/score"
        },
        "text": {
          "type": "string",
          "minLength": 1
        }
      }
    },
    "period": {
      "type": "object",
      "required": [
        "periodId",
        "name",
        "startOn",
        "endOn"
      ],
      "properties": {
        "periodId": {
          "$ref": "common.schema.json#/$defs/code"
        },
        "name": {
          "type": "string",
          "minLength": 1
        },
        "startOn": {
          "$ref": "common.schema.json#/$defs/date"
        },
        "endOn": {
          "$ref": "common.schema.json#/$defs/date"
        },
        "goalDeadline": {
          "$ref": "common.schema.json#/$defs/date"
        },
        "selfDeadline": {
          "$ref": "common.schema.json#/$defs/date"
        },
        "firstDeadline": {
          "$ref": "common.schema.json#/$defs/date"
        },
        "secondDeadline": {
          "$ref": "common.schema.json#/$defs/date"
        },
        "calibrationDeadline": {
          "$ref": "common.schema.json#/$defs/date"
        },
        "feedbackDeadline": {
          "$ref": "common.schema.json#/$defs/date"
        },
        "status": {
          "enum": [
            "preparing",
            "goal_setting",
            "evaluating",
            "calibrating",
            "finalized",
            "feedback",
            "closed"
          ]
        }
      }
    },
    "rating": {
      "type": "object",
      "required": [
        "rank",
        "minScore"
      ],
      "properties": {
        "rank": {
          "type": "string",
          "minLength": 1
        },
        "minScore": {
          "type": "number",
          "minimum": 0
        },
        "targetPercent": {
          "type": "number",
          "minimum": 0,
          "maximum": 100
        },
        "raiseFactor": {
          "type": "number"
        },
        "bonusFactor": {
          "type": "number"
        },
        "description": {
          "type": "string"
        }
      }
    },
    "assignment": {
      "type": "object",
      "required": [
        "assignmentId",
        "periodId",
        "employeeNo",
        "stage",
        "inputterNo",
        "status"
      ],
      "properties": {
        "assignmentId": {
          "$ref": "common.schema.json#/$defs/ulid"
        },
        "periodId": {
          "$ref": "common.schema.json#/$defs/code"
        },
        "employeeNo": {
          "$ref": "common.schema.json#/$defs/code"
        },
        "stage": {
          "$ref": "common.schema.json#/$defs/stage"
        },
        "inputterNo": {
          "$ref": "common.schema.json#/$defs/code"
        },
        "target": {
          "type": "string"
        },
        "targetKind": {
          "enum": [
            "self",
            "pending",
            "file",
            "invalid"
          ]
        },
        "status": {
          "enum": [
            "not_distributed",
            "in_progress",
            "submitted",
            "collected",
            "returned",
            "cancelled"
          ]
        },
        "distributedAt": {
          "$ref": "common.schema.json#/$defs/dateTime"
        },
        "submittedAt": {
          "$ref": "common.schema.json#/$defs/dateTime"
        },
        "collectedAt": {
          "$ref": "common.schema.json#/$defs/dateTime"
        },
        "memo": {
          "type": "string"
        },
        "employeeName": {
          "type": "string"
        },
        "inputterName": {
          "type": "string"
        },
        "inputterEmail": {
          "type": "string"
        }
      }
    },
    "goal": {
      "type": "object",
      "required": [
        "goalId",
        "periodId",
        "employeeNo",
        "categoryCode"
      ],
      "properties": {
        "goalId": {
          "$ref": "common.schema.json#/$defs/ulid"
        },
        "periodId": {
          "$ref": "common.schema.json#/$defs/code"
        },
        "employeeNo": {
          "$ref": "common.schema.json#/$defs/code"
        },
        "categoryCode": {
          "$ref": "common.schema.json#/$defs/code"
        },
        "title": {
          "type": "string",
          "minLength": 1
        },
        "measure": {
          "type": "string"
        },
        "weight": {
          "$ref": "common.schema.json#/$defs/positiveWeight"
        },
        "approval": {
          "enum": [
            "pending",
            "approved",
            "returned"
          ]
        },
        "midReview": {
          "type": "string"
        },
        "dueOn": {
          "$ref": "common.schema.json#/$defs/date"
        },
        "parentGoalId": {
          "$ref": "common.schema.json#/$defs/ulid"
        },
        "midProgress": {
          "$ref": "common.schema.json#/$defs/percent"
        },
        "selfAchievement": {
          "$ref": "common.schema.json#/$defs/percent"
        },
        "firstAchievement": {
          "$ref": "common.schema.json#/$defs/percent"
        },
        "approvalComment": {
          "type": "string"
        },
        "difficulty": {
          "$ref": "common.schema.json#/$defs/code"
        }
      }
    },
    "detail": {
      "type": "object",
      "required": [
        "detailId",
        "periodId",
        "employeeNo",
        "categoryCode",
        "itemName",
        "weight"
      ],
      "properties": {
        "detailId": {
          "$ref": "common.schema.json#/$defs/ulid"
        },
        "periodId": {
          "$ref": "common.schema.json#/$defs/code"
        },
        "employeeNo": {
          "$ref": "common.schema.json#/$defs/code"
        },
        "departmentCode": {
          "$ref": "common.schema.json#/$defs/code"
        },
        "gradeCode": {
          "$ref": "common.schema.json#/$defs/code"
        },
        "firstEvaluatorNo": {
          "$ref": "common.schema.json#/$defs/code"
        },
        "secondEvaluatorNo": {
          "$ref": "common.schema.json#/$defs/code"
        },
        "categoryCode": {
          "$ref": "common.schema.json#/$defs/code"
        },
        "itemCode": {
          "$ref": "common.schema.json#/$defs/code"
        },
        "goalId": {
          "$ref": "common.schema.json#/$defs/ulid"
        },
        "itemName": {
          "type": "string",
          "minLength": 1
        },
        "weight": {
          "$ref": "common.schema.json#/$defs/positiveWeight"
        },
        "selfScore": {
          "$ref": "common.schema.json#/$defs/score"
        },
        "selfComment": {
          "type": "string"
        },
        "firstScore": {
          "$ref": "common.schema.json#/$defs/score"
        },
        "firstComment": {
          "type": "string"
        },
        "secondScore": {
          "$ref": "common.schema.json#/$defs/score"
        },
        "secondComment": {
          "type": "string"
        },
        "adoptedScore": {
          "$ref": "common.schema.json#/$defs/score"
        },
        "difficultyFactor": {
          "description": "目標の難易度の係数のスナップショット（spec/10-process.md。0.3）",
          "$ref": "common.schema.json#/$defs/positiveWeight"
        },
        "selfSource": {
          "type": "string"
        },
        "firstSource": {
          "type": "string"
        },
        "secondSource": {
          "type": "string"
        },
        "selfCollectedAt": {
          "$ref": "common.schema.json#/$defs/dateTime"
        },
        "firstCollectedAt": {
          "$ref": "common.schema.json#/$defs/dateTime"
        },
        "secondCollectedAt": {
          "$ref": "common.schema.json#/$defs/dateTime"
        }
      }
    },
    "result": {
      "type": "object",
      "required": [
        "periodId",
        "employeeNo"
      ],
      "properties": {
        "periodId": {
          "$ref": "common.schema.json#/$defs/code"
        },
        "employeeNo": {
          "$ref": "common.schema.json#/$defs/code"
        },
        "categoryScores": {
          "type": "object",
          "additionalProperties": {
            "type": "number"
          }
        },
        "totalScore": {
          "type": "number",
          "minimum": 0
        },
        "provisionalRank": {
          "type": "string"
        },
        "complete": {
          "type": "boolean"
        },
        "adjustedRank": {
          "type": "string"
        },
        "adjustReason": {
          "type": "string"
        },
        "finalRank": {
          "type": "string"
        },
        "finalized": {
          "type": "boolean"
        },
        "overallComment": {
          "type": "string"
        },
        "selfOverallComment": {
          "type": "string"
        },
        "firstOverallComment": {
          "type": "string"
        },
        "secondOverallComment": {
          "type": "string"
        },
        "disclosedAt": {
          "$ref": "common.schema.json#/$defs/dateTime"
        },
        "acknowledgedAt": {
          "$ref": "common.schema.json#/$defs/dateTime"
        }
      }
    },
    "interview": {
      "type": "object",
      "required": [
        "interviewId",
        "date",
        "employeeNo"
      ],
      "properties": {
        "interviewId": {
          "$ref": "common.schema.json#/$defs/ulid"
        },
        "date": {
          "$ref": "common.schema.json#/$defs/date"
        },
        "employeeNo": {
          "$ref": "common.schema.json#/$defs/code"
        },
        "interviewerNo": {
          "$ref": "common.schema.json#/$defs/code"
        },
        "kind": {
          "enum": [
            "one_on_one",
            "goal",
            "midterm",
            "feedback"
          ]
        },
        "content": {
          "type": "string"
        },
        "nextActions": {
          "type": "string"
        },
        "periodId": {
          "$ref": "common.schema.json#/$defs/code"
        },
        "stepCode": {
          "$ref": "common.schema.json#/$defs/code"
        },
        "scheduledOn": {
          "$ref": "common.schema.json#/$defs/date"
        },
        "acknowledgedAt": {
          "$ref": "common.schema.json#/$defs/dateTime"
        }
      }
    },
    "historyRow": {
      "type": "object",
      "required": [
        "at",
        "action"
      ],
      "properties": {
        "at": {
          "$ref": "common.schema.json#/$defs/dateTime"
        },
        "actor": {
          "type": "string"
        },
        "action": {
          "type": "string",
          "minLength": 1
        },
        "target": {
          "type": "string"
        },
        "count": {
          "type": "number"
        },
        "detail": {
          "type": "string"
        }
      }
    },
    "submission": {
      "type": "object",
      "required": [
        "assignmentId",
        "employeeNo",
        "stage",
        "submitted"
      ],
      "properties": {
        "assignmentId": {
          "$ref": "common.schema.json#/$defs/ulid"
        },
        "employeeNo": {
          "$ref": "common.schema.json#/$defs/code"
        },
        "stage": {
          "$ref": "common.schema.json#/$defs/stage"
        },
        "submitted": {
          "type": "boolean"
        },
        "submittedAt": {
          "$ref": "common.schema.json#/$defs/dateTime"
        }
      }
    },
    "processStep": {
      "description": "評価の流れのステップ（spec/10-process.md）",
      "type": "object",
      "required": [
        "stepCode",
        "order",
        "kind",
        "name",
        "actor"
      ],
      "properties": {
        "stepCode": {
          "$ref": "common.schema.json#/$defs/code"
        },
        "order": {
          "type": "number"
        },
        "kind": {
          "enum": [
            "goal_setting",
            "mid_review",
            "interview",
            "self",
            "first",
            "second",
            "calibration",
            "finalize",
            "disclosure"
          ]
        },
        "name": {
          "type": "string",
          "minLength": 1
        },
        "actor": {
          "enum": [
            "self",
            "first_evaluator",
            "second_evaluator",
            "hr"
          ]
        },
        "approver": {
          "enum": [
            "first_evaluator",
            "second_evaluator",
            "hr"
          ]
        },
        "secondMode": {
          "enum": [
            "rescore",
            "approve_only"
          ]
        },
        "interviewKind": {
          "enum": [
            "one_on_one",
            "goal",
            "midterm",
            "feedback"
          ]
        },
        "parallel": {
          "type": "boolean"
        },
        "deadlineDays": {
          "type": "integer",
          "minimum": 0
        },
        "required": {
          "type": "boolean"
        },
        "active": {
          "type": "boolean"
        }
      }
    },
    "stepState": {
      "description": "期 × 社員 × ステップの進み具合（spec/10-process.md）",
      "type": "object",
      "required": [
        "periodId",
        "employeeNo",
        "stepCode",
        "status"
      ],
      "properties": {
        "periodId": {
          "$ref": "common.schema.json#/$defs/code"
        },
        "employeeNo": {
          "$ref": "common.schema.json#/$defs/code"
        },
        "stepCode": {
          "$ref": "common.schema.json#/$defs/code"
        },
        "status": {
          "enum": [
            "not_started",
            "in_progress",
            "submitted",
            "approved",
            "returned",
            "done",
            "skipped"
          ]
        },
        "actorNo": {
          "$ref": "common.schema.json#/$defs/code"
        },
        "approverNo": {
          "$ref": "common.schema.json#/$defs/code"
        },
        "startedAt": {
          "$ref": "common.schema.json#/$defs/dateTime"
        },
        "submittedAt": {
          "$ref": "common.schema.json#/$defs/dateTime"
        },
        "approvedAt": {
          "$ref": "common.schema.json#/$defs/dateTime"
        },
        "returnedAt": {
          "$ref": "common.schema.json#/$defs/dateTime"
        },
        "returnReason": {
          "type": "string"
        },
        "doneAt": {
          "$ref": "common.schema.json#/$defs/dateTime"
        },
        "memo": {
          "type": "string"
        }
      }
    },
    "goalScaleRow": {
      "description": "達成率 → 評点の換算表の 1 行（spec/10-process.md）",
      "type": "object",
      "required": [
        "minRate",
        "score"
      ],
      "properties": {
        "minRate": {
          "$ref": "common.schema.json#/$defs/percent"
        },
        "score": {
          "$ref": "common.schema.json#/$defs/score"
        }
      }
    },
    "goalDifficulty": {
      "description": "目標の難易度と係数の 1 行（spec/10-process.md。0.3）",
      "type": "object",
      "required": [
        "code",
        "name",
        "factor"
      ],
      "properties": {
        "code": {
          "$ref": "common.schema.json#/$defs/code"
        },
        "name": {
          "type": "string",
          "minLength": 1
        },
        "factor": {
          "$ref": "common.schema.json#/$defs/positiveWeight"
        },
        "order": {
          "type": "integer"
        },
        "description": {
          "type": "string"
        },
        "active": {
          "type": "boolean"
        }
      }
    }
  },
  "allOf": [
    {
      "description": "マスターでだけ必須の列（配布のファイルは列を絞る。目標の空き枠は title が空。spec/08-distribution-file.md）",
      "if": {
        "properties": {
          "fileType": {
            "const": "master"
          }
        }
      },
      "then": {
        "properties": {
          "tables": {
            "properties": {
              "details": {
                "items": {
                  "required": [
                    "departmentCode",
                    "gradeCode"
                  ]
                }
              },
              "periods": {
                "items": {
                  "required": [
                    "status"
                  ]
                }
              },
              "goals": {
                "items": {
                  "required": [
                    "title"
                  ]
                }
              }
            }
          }
        }
      }
    }
  ]
}
