import { useMutation } from '@apollo/client';
import { flattenError } from '@theorchard/suite-frontend';
import {
    UpdateNrSoundRecording, UpdateNrSoundRecordingVariables
} from 'src/data/mutations/soundRecording/__generated__/UpdateNrSoundRecording';
import updateNrSoundRecording from './updateNrSoundRecording.gql';

export const useUpdateSoundRecordingMutation = (variables: UpdateNrSoundRecordingVariables) => {
    const [updateSong, songResult] = useMutation<UpdateNrSoundRecording, UpdateNrSoundRecordingVariables>(
        updateNrSoundRecording, { variables }
    );

    const { data, loading, error } = songResult;

    return {
        updateSong,
        data: data?.updateNrSoundRecording,
        loading,
        error: error && flattenError(error)
    };
};
