import type { GlideDecision, TaskId } from '@/domain/glide';

import { useTaskStore } from './task-store';

/**
 * The task repository — the single imperative write surface the UI talks to, and
 * the seam a future Convex sync engine decorates. Today each call delegates straight
 * to the local store; later it can also write-through a mutation queue and let the
 * sync engine reconcile remote changes back into the same store — with nothing above
 * this line changing (the deep-module boundary from TASTE.md).
 *
 * Reads are reactive and go through `useBoard`; these are the writes, mirroring the
 * old Convex mutations one-for-one. Calling `getState()` outside React is the
 * standard Zustand pattern for imperative access.
 */
export const tasks = {
  createTask: (title: string) => useTaskStore.getState().createTask(title),
  assess: (id: TaskId, decision: GlideDecision) => useTaskStore.getState().assess(id, decision),
  complete: (id: TaskId) => useTaskStore.getState().complete(id),
  startPlanSession: () => useTaskStore.getState().startPlanSession(),
  ensureStarterTasks: () => useTaskStore.getState().ensureStarterTasks(),
};
