/* ============================================================================= * M01_LB_Blocks.ts * 로직 만들기 판 — 로직 줄 ↔ 블록(① 입력값 ② 표 조회 ③ 계산 ④ 항목 연결 ⑤ 결과값) 읽기 · 쓰기 * DOM 없음 · 모양은 `docs/raw/M01_쉬운단가/로직판_A_설계초안.md` 7-1 · `로직판_A_정함.md` 그대로 * ========================================================================== */ import type { LogicInput, LogicRow } from "../M01_MasterData_UI_Logic_Api"; import type { CondRead } from "../EasyCalc/M01_EasyCalc_Cond"; import type { EasyDoc } from "../EasyCalc/M01_EasyCalc_Model"; /** 값이 오는 곳 */ export type LbRef = | { k: "input"; name: string } // ① 입력값 | { k: "fixed"; value: number | string } // 고정값 | { k: "lookup"; id: string } // ② 표 조회 결과 | { k: "calc"; name: string } // ③ 이름 붙은 계산값(중간) | { k: "logic"; key: string; field: string | null } // 다른 로직 결과값(.노무비 등) | { k: "cost"; name: "노무비" | "재료비" | "경비" | "사람줄합" }; /** 블록으로 못 나눈 조각 — 원래 글 그대로 */ export interface LbExpr { k: "expr"; text: string; } /** 식 자리 — 중간 · 호표 수량 · 덧줄 · 결과 · 장비/일위대가 요소 */ export type LbPart = "중간" | "수량" | "비율" | "결과" | "요소"; export interface LbLookup { /** 화면 번호 · 저장 안 함 */ id: string; /** QF000421 · 현장 사본이면 QX… */ table: string; conds: { col: string; from: LbRef | LbExpr }[]; /** 결과 칸 */ col: string; at: { part: LbPart; index: number; start: number; end: number }[]; } export type LbCalcKind = "값" | "곱나눔" | "할증" | "더하기" | "조건목록" | "최소최대" | "올림" | "단계"; export interface LbCalc { /** 중간 이름 · 수량 자리면 null */ name: string | null; kind: LbCalcKind; /** 곱나눔 · 더하기 · 할증(바탕 · 율) */ parts: (LbRef | LbExpr)[]; ops?: ("*" | "/" | "+" | "-")[]; /** 조건목록 · 최소최대 · 올림 — Cond 것 그대로 */ cond?: CondRead; at: { part: Exclude; index: number }; /** 원래 글(안 고치면 그대로 씀) */ text: string; } export interface LbLogic { /** ④ 항목 · ⑤ 금액 — Model 것 그대로 */ doc: EasyDoc; /** ① */ inputs: LogicInput[]; /** ② */ lookups: LbLookup[]; /** ③ */ calcs: LbCalc[]; /** ⑤ */ result: { kind: "금액"; unit: string } | { kind: "값"; unit: string; calc: LbCalc }; /** 못 읽은 까닭(쉬운 말) — 비면 다 읽힘 */ blocked: string[]; } /** 원문 표 칸 고치기(메모리 사본) */ export interface TableEdit { table: string; row: number; col: string; value: number | string | [number | null, number | null]; } const notReady = (): never => { throw new Error("준비 중"); }; /** 로직 줄 → 블록 */ export function readLogic( _row: LogicRow, _meta: { key: string | null; version: string | null; isBase: boolean }, ): LbLogic { return notReady(); } /** 블록 → 로직 줄 — 고친 조각 자리만 글 갈아끼우기 */ export function writeLogic(_lb: LbLogic): LogicRow { return notReady(); } /** 단계 안내가 채울 빈 로직 */ export function newLogic(_name?: string, _per?: string): LbLogic { return notReady(); } /** 표 조회 조건 칸 하나 바꾸기 · from = null 은 조건 뺌(무관) */ export function setCond( _lb: LbLogic, _lookupId: string, _col: string, _from: LbRef | LbExpr | null, ): LbLogic { return notReady(); } /** 계산 하나 바꾸기 — patch 의 틀 · 조각 · 조건으로 그 자리 글을 다시 짬 */ export function setCalc(_lb: LbLogic, _calc: LbCalc, _patch: Partial): LbLogic { return notReady(); } /** 표 조회가 보는 표 바꾸기(현장 사본 등) */ export function setLookupTable(_lb: LbLogic, _lookupId: string, _table: string): LbLogic { return notReady(); }