/**
 * @bytelyst/client-encrypt — Type guards
 *
 * Compatible with @bytelyst/field-encrypt isEncryptedField() on the server.
 */

import type { EncryptedField } from './types.js';

/** Check if a value is an EncryptedField object. */
export function isEncryptedField(value: unknown): value is EncryptedField {
  if (typeof value !== 'object' || value === null) return false;
  const obj = value as Record<string, unknown>;
  return (
    obj.__encrypted === true &&
    obj.v !== undefined &&
    obj.alg !== undefined &&
    typeof obj.ct === 'string' &&
    typeof obj.iv === 'string' &&
    typeof obj.tag === 'string' &&
    typeof obj.dekId === 'string'
  );
}
