/** Typed errors thrown by the tenant helpers so callers can map them to HTTP / ack codes. */

/** The row changed since the caller read it (optimistic concurrency on `version`). */
export class ConflictError extends Error {
  readonly code = 'CONFLICT' as const;
  override readonly name = 'ConflictError';

  constructor(
    readonly entity: string,
    readonly id: string,
    readonly expectedVersion: number,
    readonly actualVersion: number,
  ) {
    super(`${entity} ${id} was modified (expected version ${expectedVersion}, found ${actualVersion})`);
  }
}

/** The row does not exist, or belongs to another venue (deliberately indistinguishable). */
export class NotFoundError extends Error {
  readonly code = 'NOT_FOUND' as const;
  override readonly name = 'NotFoundError';

  constructor(
    readonly entity: string,
    readonly id: string,
  ) {
    super(`${entity} ${id} not found`);
  }
}
