import { StudioProjectState } from '../types';

/**
 * Creates an action that updates the metadata of a studio project state.
 * This function merges new metadata with the existing metadata, preserving any
 * existing metadata fields that aren't overwritten by the new metadata.
 *
 * @param metadata - The new metadata to merge with the existing metadata
 * @returns A function that takes the current state and returns a new state with updated metadata
 */
export default function assignMetadata(
  metadata: StudioProjectState['metadata']
) {
  return (state: StudioProjectState) => ({
    ...state,
    metadata: {
      ...state.metadata,
      ...metadata,
    },
  });
}
