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

export const useCreateSoundRecordingMutation = (variables: CreateNrSoundRecordingVariables) => {
    const [createSong, songResult] = useMutation<CreateNrSoundRecording, CreateNrSoundRecordingVariables>(
        createNrSoundRecording, { variables }
    );

    const { data, loading, error } = songResult;

    return {
        createSong,
        data: data?.createNrSoundRecording,
        loading,
        error: error && flattenError(error)
    };
};
