/*
 * Copyright (C) 2026 UBports Foundation.
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License version 3 as
 * published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

#pragma once

#include "../RcloneClient.h"

#include <lomiri/storage/provider/ProviderBase.h>

#include <boost/thread/future.hpp>

#include <functional>
#include <memory>
#include <string>

class Vendor
{
public:
    using ConnStringCallback =
        std::function<void(std::string const& fs,
                           boost::exception_ptr const& error)>;
    using WithFsCallback = std::function<void(std::string const& fs)>;

    virtual ~Vendor();

    // Dispatch a vendor based on the account context.
    static std::shared_ptr<Vendor> for_context(
        lomiri::storage::provider::Context const& ctx);

    // Wraps get_conn_string() and handles errors.
    template <typename T>
    void with_fs(std::shared_ptr<RcloneClient> const& client,
                 std::shared_ptr<boost::promise<T>> const& promise,
                 WithFsCallback body);

protected:
    // Next unique remote identifier.
    static std::string next_remote_name(std::string const& prefix);

    // Get the rclone fs string for the created remote or an anonymous fs.
    virtual void get_conn_string(std::shared_ptr<RcloneClient> const& client,
                                 ConnStringCallback cb) = 0;
};
