
namespace E {
    public const string AG_SERVICE_TYPE_CALENDAR = "calendar";
    public const string AG_SERVICE_TYPE_CONTACTS = "contacts";
    public const string AG_SERVICE_TYPE_MAIL = "mail";
}

namespace E.POAUtils {
    public static bool check_oauth2_support (Ag.AccountService account_service) {
        var mechanism = account_service.get_auth_data ().get_mechanism ();
        if (mechanism == "web_server" || mechanism == "user_agent") {
            return true;
        } else {
            return false;
        }
    }

    /* Determine an appropriate service type based on
     * which extensions are present in the ESource. */
    public static string? get_service_type_from_source (E.Source source) {
        if (source.has_extension (E.SOURCE_EXTENSION_ADDRESS_BOOK))
            return AG_SERVICE_TYPE_CONTACTS;

        if (source.has_extension (E.SOURCE_EXTENSION_CALENDAR))
            return AG_SERVICE_TYPE_CALENDAR;

        if (source.has_extension (E.SOURCE_EXTENSION_MEMO_LIST))
            return AG_SERVICE_TYPE_CALENDAR;

        if (source.has_extension (E.SOURCE_EXTENSION_TASK_LIST))
            return AG_SERVICE_TYPE_CALENDAR;

        if (source.has_extension (E.SOURCE_EXTENSION_MAIL_ACCOUNT))
            return AG_SERVICE_TYPE_MAIL;

        if (source.has_extension (E.SOURCE_EXTENSION_MAIL_IDENTITY))
            return AG_SERVICE_TYPE_MAIL;

        if (source.has_extension (E.SOURCE_EXTENSION_MAIL_TRANSPORT))
            return AG_SERVICE_TYPE_MAIL;

        return null;
}
}