/**
 * @bytelyst/field-encrypt — Type guards
 *
 * Utility to detect encrypted vs plaintext fields during migration.
 */

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

/**
 * Check if a value is an EncryptedField.
 *
 * Use this in repositories to handle both encrypted and plaintext fields
 * during the migration period.
 */
export function isEncryptedField(value: unknown): value is EncryptedField {
  return (
    typeof value === 'object' &&
    value !== null &&
    '__encrypted' in value &&
    (value as Record<string, unknown>).__encrypted === true &&
    'v' in value &&
    'ct' in value &&
    'iv' in value &&
    'tag' in value &&
    'dekId' in value
  );
}
