/*
 * SPDX-FileCopyrightText: 2025 The HedgeDoc developers (see AUTHORS file)
 *
 * SPDX-License-Identifier: AGPL-3.0-only
 */
import type { NoteDetails } from '../types'
import type { NoteMetadataInterface } from '@hedgedoc/commons'

/**
 * Builds a {@link NoteDetails} redux state from a note metadata DTO received from the HTTP API.
 * @param state The previous state to update.
 * @param noteMetadata The updated metadata from the API.
 * @return An updated {@link NoteDetails} redux state.
 */
export const buildStateFromMetadataUpdate = (state: NoteDetails, noteMetadata: NoteMetadataInterface): NoteDetails => {
  return {
    ...state,
    lastUpdatedBy: noteMetadata.lastUpdatedBy,
    permissions: noteMetadata.permissions,
    editedBy: noteMetadata.editedBy,
    primaryAlias: noteMetadata.primaryAlias,
    aliases: noteMetadata.aliases,
    title: noteMetadata.title,
    version: noteMetadata.version,
    createdAt: noteMetadata.createdAt,
    updatedAt: noteMetadata.updatedAt
  }
}
