/**
* `robot_error_reports` を読むときの `select`(指示書AU 段階0-4。§11 Q6。D-158)。
*
* ★★`robot_id` と `robot` リレーションを読まないこと★★ —
* 先方の DDL では `robot_id` が NULL 可になった(TeamWorks 第11回 P-8 b)が、
* `prisma/schema.prisma` は NOT NULL のまま(`db pull` は監督が行う。本リポジトリではスキーマを変えない)。
* ★`select` なし(=全列)や `include` で読むと、NULL の行が1件入っただけで読み取りが落ちる★。
* ★読む列を `select` で絞っておけば、NULL の行が入っても落ちない★。
*
* ★読み取りは必ずこのファイルの定数を使う★(`lib/db/index.ts` の `robotErrorReport.findMany` /
* `findUnique`)。列を足すときも ★`robot_id` / `robot` は足さない★。
* `lib/db/__tests__/robot-error-select.test.ts` が固定している。
* ★書き込み(`lib/db/robot-error-write.ts` の `updateMany`)は対象外★(行を読まない)。
*/
import type { Prisma } from "@/lib/generated/prisma/client";
/**
* 本清掃行ごとのエラー件数(`errorCountByMainTimetable()`)に要る列。
* `reportKpis()` / `facilityPerformance()` の当期が使う。
*/
export const ROBOT_ERROR_COUNT_SELECT = {
clean_timetable_id: true,
} as const satisfies Prisma.RobotErrorReportSelect;
/**
* 清掃詳細ログのロボット状態(`RobotErrorLike`。`cleanLogs()`)に要る列。
*/
export const ROBOT_ERROR_STATUS_SELECT = {
clean_timetable_id: true,
error_type: true,
errored_at: true,
} as const satisfies Prisma.RobotErrorReportSelect;
/**
* 当期のエラー内訳(`ErrorReportLike`。`countMainErrorTypesInRange()`。`errorBreakdown()`)に要る列。
* ★`errored_at` / `created_at` は `ErrorReportLike`(`PrecheckDetectedAtSource`)の型が要求するので読む★。
*/
export const ROBOT_ERROR_TYPE_SELECT = {
clean_timetable_id: true,
error_type: true,
errored_at: true,
created_at: true,
} as const satisfies Prisma.RobotErrorReportSelect;
/**
* 事前チェックのアラート行(`PrecheckErrorRowSource`。`precheckItemFromErrorRow()`)に要る列。
* ★`prechecks()`(一覧)と `precheckItemById()`(PATCH の前後の読み取り)が同じ定数を使う★
* (行の作り方を1本にしたのと同じ理由。指示書AT 段階4-1)。
* ★`facility` は施設名だけ★(旧: `include: { facility: true }`)。
*/
export const ROBOT_ERROR_PRECHECK_ROW_SELECT = {
error_id: true,
clean_timetable_id: true,
serial_number: true,
facility_id: true,
facility: { select: { facility_name: true } },
error_type: true,
errored_at: true,
created_at: true,
status: true,
responded_at: true,
resolved_at: true,
comment: true,
} as const satisfies Prisma.RobotErrorReportSelect;
/**
* エラー一覧の1段目(キーだけ。指示書AW D8)。絞り込み・並べ替えに要る列だけ。
* ★`clean_timetable_id` は並べ替えには使わないが、select の共通テスト(紐づけのキーを含む)のために読む★
*/
export const ROBOT_ERROR_LIST_KEY_SELECT = {
error_id: true,
clean_timetable_id: true,
facility_id: true,
error_type: true,
errored_at: true,
created_at: true,
status: true,
} as const satisfies Prisma.RobotErrorReportSelect;
/**
* エラー一覧の2段目・PATCH の前後の読み取り(`errorReportItemFromRow()`)に要る列。
* ★`errorReports()` と `errorReportById()` が同じ定数を使う★(行の作り方を1本にする。AT 段階4-1 と同じ理由)
* ★`robot_id` / `robot` / `section` を足さない★(指示書AW 4-1。`robot_id` が NULL の行で落ちる)
*/
export const ROBOT_ERROR_LIST_ROW_SELECT = {
error_id: true,
clean_timetable_id: true,
serial_number: true,
facility_id: true,
facility: { select: { facility_name: true } },
error_type: true,
error_level: true,
errored_at: true,
created_at: true,
status: true,
responded_at: true,
resolved_at: true,
comment: true,
} as const satisfies Prisma.RobotErrorReportSelect;