void HandlePollCompleteResponse(
        FSM & fsm,
        const mf::api::upload::poll_upload::Response & response
    )
{
    if (response.quickkey)
    {
        if (response.filename)
        {
            // Filename was changed
            fsm.ProcessEvent(event::PollComplete{
                *response.quickkey,
                *response.filename
                });
        }
        else
        {
            fsm.ProcessEvent(event::PollComplete{
                *response.quickkey,
                fsm.filename()
                });
        }
    }
    else
    {
        fsm.ProcessEvent(event::Error{
            make_error_code(api::api_code::ContentInvalidData),
            "Successful response missing quickkey"
            });
    }
}
    void operator()(
            Event const &,
            FSM & fsm,
            SourceState&,
            TargetState&
        )
    {
        namespace instant = mf::api::upload::instant;

        auto request = instant::Request( fsm.filename(), fsm.hash(),
            fsm.filesize());

        switch (fsm.onDuplicateAction())
        {
            case OnDuplicateAction::Fail:
                // This is the default, same as "skip" and doesn't need to be
                // set.
                break;
            case OnDuplicateAction::Replace:
                request.SetActionOnDuplicate(instant::ActionOnDuplicate::Replace);
                break;
            case OnDuplicateAction::AutoRename:
                request.SetActionOnDuplicate(instant::ActionOnDuplicate::Keep);
                break;
            default:
                assert(!"Invalid duplicate action.");
                break;
        }

        UploadTarget target_folder = fsm.targetFolder();
        boost::apply_visitor(TargetSetter(&request), target_folder);

        auto fsmp = fsm.AsFrontShared();

        fsm.GetSessionMaintainer()->Call(
            request,
            [fsmp](const instant::Response & response)
            {
                if (response.error_code)
                {
                    fsmp->ProcessEvent(event::Error{response.error_code,
                        "Failed to instant upload file."});
                }
                else
                {
                    fsmp->ProcessEvent(event::InstantSuccess{ response.quickkey,
                        response.filename });
                }
            });
    }
void HandlePollCompleteResponse(
        FSM & fsm,
        const mf::api::upload::poll_upload::Response & response)
{
    assert(response.response_data);
    const auto & response_data = *response.response_data;

    if (!response_data.quickkey)
    {
        fsm.ProcessEvent(
                event::Error{make_error_code(api::api_code::ContentInvalidData),
                             "Successful response missing quickkey"});
    }
    else if (!response_data.revision)
    {
        fsm.ProcessEvent(
                event::Error{make_error_code(api::api_code::ContentInvalidData),
                             "Successful response missing revision"});
    }
    else
    {
        if (response_data.filename)
        {
            // Filename was changed
            fsm.ProcessEvent(event::PollComplete{*response_data.quickkey,
                                                 *response_data.filename,
                                                 *response_data.revision});
        }
        else
        {
            fsm.ProcessEvent(event::PollComplete{*response_data.quickkey,
                                                 fsm.filename(),
                                                 *response_data.revision});
        }
    }
}