import useSend from '../useSend'
import { composeSendRateURL, processSendRate } from '../../api/sendRate'
import { isSendRateResponse } from '../../api/sendRate/types'

function useSendRate() {
    const { doSend, ...rest } = useSend(
        composeSendRateURL(),
        'POST',
        true,
        isSendRateResponse,
        processSendRate,
    )

    const doSendRate = (rate: number, user_id: number) => (
        doSend({}, {
            body: JSON.stringify({
                rate,
                user_id,
            }),
            headers: {
                'Content-Type': 'application/json',
            },

        })
    )


    return {
        doSendRate,
        ...rest,
    }
}

export default useSendRate
