export type Asuka3DStickerProjectionStrategy = 'face-net' | 'target-bound-projector';

export interface Asuka3DStickerProjectionStrategyInput {
  targetMeshId?: string | null;
  selectedTriangleCount?: number | null;
  targetIsNamedPrintSurface?: boolean;
}

export const TARGET_BOUND_STICKER_RENDER_POLICY = Object.freeze({
  zOffset: 0,
  zOffsetUnits: 0,
  surfaceShellOffsetRatio: 0.002,
  surfaceShellOffsetMin: 0.0008,
  surfaceShellOffsetMax: 0.004,
  depthFunction: 'lequal' as const,
  surfaceNormalThreshold: -0.2,
  surfaceDepthRatio: 0.22,
  rejectAdjacentFaces: false,
  cameraRelativeFlipU: false,
  textureSampleFlipU: true,
  wrapAcrossOppositeFaces: false,
  dragConstraint: 'target-mesh' as const,
});

export function resolve3DStickerProjectionStrategy(
  input: Asuka3DStickerProjectionStrategyInput,
): Asuka3DStickerProjectionStrategy {
  const targetMeshId = String(input?.targetMeshId ?? '').trim().toLowerCase();
  const selectedTriangleCount = Math.max(0, Math.floor(Number(input?.selectedTriangleCount) || 0));
  const hasExplicitMeshTarget = !!targetMeshId && targetMeshId !== 'product';
  if (!hasExplicitMeshTarget || input?.targetIsNamedPrintSurface === true) return 'face-net';
  return selectedTriangleCount > 512 ? 'target-bound-projector' : 'face-net';
}
