import type { AnswerMap, ResponseData, ResponseStatus, ValidationResult } from "./types.ts"; import type { Assessment } from "./assessment.ts"; /** * A respondent's answers to one assessment. * * Supports answering one question at a time (`answer`) or all at once * (`answerAll`), validates every value against the assessment's option * scale, and becomes immutable once submitted. */ export declare class AssessmentResponse { readonly assessment: Assessment; readonly respondentId?: string; readonly meta?: Record; readonly startedAt: Date; private readonly values; private submittedTime?; private state; constructor(assessment: Assessment, options?: { respondentId?: string; meta?: Record; startedAt?: Date; }); /** Answers keyed by question id (a copy — mutate via `answer`). */ get answers(): AnswerMap; get submittedAt(): Date | undefined; get isSubmitted(): boolean; /** Current lifecycle state (see `ResponseStatus`). */ get status(): ResponseStatus; /** * Answers a single question. Re-answering replaces the previous value. * @throws PsytoolsError `already_submitted` | `unknown_question` | `invalid_value` */ answer(questionId: string, value: number): this; /** * Answers many questions at once. Accepts a map of question id -> value, * or an array of values in question order. */ answerAll(answers: AnswerMap | number[]): this; /** Removes an answer (e.g. respondent deselects a choice). */ clearAnswer(questionId: string): this; /** Ids of required questions that are not answered yet. */ unanswered(): string[]; /** Completion ratio in `[0, 1]` over all questions. */ progress(): number; isComplete(): boolean; /** * Validates the current answers against the assessment: every answered * value must belong to the question's option scale, and (unless * `partial`) every required question must be answered. */ validate(options?: { partial?: boolean; }): ValidationResult; /** * Validates and finalizes the response. After submission the response is * immutable. Pass `allowIncomplete` to submit with unanswered optional-use * cases (answered values are still validated). * @throws PsytoolsError `already_submitted` | `invalid_response` */ submit(options?: { allowIncomplete?: boolean; submittedAt?: Date; }): this; /** Plain serializable data (used by `JSON.stringify`). */ toJSON(): ResponseData; /** Serializes to a JSON string (for DB storage etc.). */ stringify(space?: number): string; /** * Restores a response from serialized data, validating every answer * against the assessment. * @throws PsytoolsError `invalid_json` | `assessment_mismatch` | `unknown_question` | `invalid_value` */ static parse(assessment: Assessment, input: string | ResponseData): AssessmentResponse; private checkAnswer; private assertMutable; private refreshState; }