/** Canonical kind names for v1 ops. */
export const KIND_LIST_V1 = 'shade.fs.list/v1' as const;
export const KIND_STAT_V1 = 'shade.fs.stat/v1' as const;
export const KIND_MKDIR_V1 = 'shade.fs.mkdir/v1' as const;
export const KIND_DELETE_V1 = 'shade.fs.delete/v1' as const;
export const KIND_MOVE_V1 = 'shade.fs.move/v1' as const;
export const KIND_READ_V1 = 'shade.fs.read/v1' as const;
export const KIND_WRITE_V1 = 'shade.fs.write/v1' as const;
export const KIND_GET_THUMBNAIL_V1 = 'shade.fs.getThumbnail/v1' as const;
export const KIND_CUSTOM_V1 = 'shade.fs.custom/v1' as const;

export const KIND_ERROR_V1 = 'shade.fs.error/v1' as const;
export const KIND_CANCEL_V1 = 'shade.fs.cancel/v1' as const;

/** Compute the response kind from a request kind: `'shade.fs.foo/v1'` → `'shade.fs.foo/v1.response'`. */
export function responseKindOf<K extends string>(kind: K): `${K}.response` {
  return `${kind}.response`;
}

/** Standard op identifier — used in `OpContext.op`. */
export type StandardOp =
  | 'list'
  | 'stat'
  | 'mkdir'
  | 'delete'
  | 'move'
  | 'read'
  | 'write'
  | 'getThumbnail';

const KIND_TO_OP: Record<string, StandardOp> = {
  [KIND_LIST_V1]: 'list',
  [KIND_STAT_V1]: 'stat',
  [KIND_MKDIR_V1]: 'mkdir',
  [KIND_DELETE_V1]: 'delete',
  [KIND_MOVE_V1]: 'move',
  [KIND_READ_V1]: 'read',
  [KIND_WRITE_V1]: 'write',
  [KIND_GET_THUMBNAIL_V1]: 'getThumbnail',
};

export function opOfKind(kind: string): StandardOp | null {
  return KIND_TO_OP[kind] ?? null;
}

/** Mutation ops require an idempotency key on retries. */
export const MUTATION_OPS = new Set<StandardOp | 'custom'>([
  'mkdir',
  'delete',
  'move',
  'write',
  'custom',
]);
