/**
 * Helpers for reading the surface texture selection out of a FurnitureItem's
 * metadata bag. Kept standalone so both the 3D mesh and the properties panel
 * can read/write the same shape without importing each other.
 *
 * Metadata key:
 *   - `surfaceTexture`: A FurnitureTexture value ('NONE' | 'WOOD_LIGHT' | …).
 *     When absent or 'NONE', the furniture uses its default solid-color material.
 */

import type { FurnitureTexture, AcUnitStyle } from '@house-plan-maker/shared';

type MetadataBag = Record<string, unknown> | null | undefined;

/** Read the surface texture from furniture metadata. Returns 'NONE' by default. */
export function getFurnitureTexture(metadata: MetadataBag): FurnitureTexture {
  if (!metadata) return 'NONE';
  const raw = metadata['surfaceTexture'];
  if (typeof raw === 'string') {
    return raw as FurnitureTexture;
  }
  return 'NONE';
}

/** Read the AC unit style from furniture metadata. Returns 'generic' by default. */
export function getAcUnitStyle(metadata: MetadataBag): AcUnitStyle {
  if (!metadata) return 'generic';
  const raw = metadata['acUnitStyle'];
  if (raw === 'lg') return 'lg';
  return 'generic';
}
