import type { IDataRectify } from "../data-rectify.interface";
import type { HandlerResponse } from "./handler-types";

export type RectifyHandlerInput = {
  subjectId: string;
  collection: string;
  field: string;
  value: unknown;
};

export function createRectifyHandler(dataRectify: IDataRectify) {
  return async (
    input: RectifyHandlerInput,
  ): Promise<HandlerResponse<{ ok: true }>> => {
    await dataRectify.updateSubjectField(
      input.subjectId,
      input.collection,
      input.field,
      input.value,
    );
    return { status: 200, body: { ok: true as const } };
  };
}
