/*****************************************************************************
 * VLCMLService.h
 * VLCMediaLibraryKit
 *****************************************************************************
 * Copyright (C) 2026 VLC authors and VideoLAN
 *
 * Authors: Felix Paul Kühne <fkuehne # videolan.org>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as published by
 * the Free Software Foundation; either version 2.1 of the License, or
 * (at your option) any later version.
 *
 * 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 Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this program; if not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
 *****************************************************************************/

#import <Foundation/Foundation.h>

typedef NS_ENUM(NSUInteger, VLCMLSortingCriteria);

@class VLCMLMedia, VLCMLSubscription;

/**
 * @brief VLCMLServiceType The type of a service.
 *
 * The type is used as the service's primary key in the database, so it must
 * never be 0.
 */
typedef NS_ENUM(UInt8, VLCMLServiceType) {
    VLCMLServiceTypePodcast = 1
};

NS_ASSUME_NONNULL_BEGIN

/**
 * @brief The VLCMLService class represents a service the user can import
 * subscriptions from, such as podcasts.
 *
 * Instances are obtained through \see{VLCMediaLibrary serviceWithType:}.
 */
@interface VLCMLService : NSObject

/**
 * @brief autoDownload Whether new media of this service should be cached
 * automatically.
 */
@property (nonatomic) BOOL autoDownloadEnabled;

/**
 * @brief newMediaNotificationEnabled Whether new content for this service
 * should issue a notification.
 *
 * Each subscription can override this setting, or inherit it.
 */
@property (nonatomic) BOOL newMediaNotificationEnabled;

/**
 * @brief maxCacheSize The maximum cache size in bytes for all subscriptions of
 * this service, or -1 if the limit isn't set for this service.
 *
 * If the limit isn't set, the global maximum cache size setting is used
 * instead. Set to -1 to unset it again.
 */
@property (nonatomic) SInt64 maxCacheSize;

- (instancetype)init NS_UNAVAILABLE;

- (VLCMLServiceType)type;

/**
 * @brief addSubscriptionWithMRL Adds a subscription to this service
 * @param mrl The MRL of the subscription's feed
 * @return YES if the subscription was added successfully
 */
- (BOOL)addSubscriptionWithMRL:(NSURL *)mrl;

/**
 * @brief subscriptions The subscriptions of this service.
 *
 * @note Subscriptions can currently only be ordered by name; the sorting
 * criteria is ignored by the media library and only \c desc is honoured. The
 * criteria parameter is kept for forward compatibility.
 */
- (nullable NSArray<VLCMLSubscription *> *)subscriptions;
- (nullable NSArray<VLCMLSubscription *> *)subscriptionsWithSortingCriteria:(VLCMLSortingCriteria)criteria
                                                                      desc:(BOOL)desc;

- (nullable NSArray<VLCMLSubscription *> *)searchSubscriptionsWithPattern:(NSString *)pattern;
- (nullable NSArray<VLCMLSubscription *> *)searchSubscriptionsWithPattern:(NSString *)pattern
                                                                    sort:(VLCMLSortingCriteria)criteria
                                                                    desc:(BOOL)desc;

- (nullable NSArray<VLCMLMedia *> *)media;
- (nullable NSArray<VLCMLMedia *> *)mediaWithSortingCriteria:(VLCMLSortingCriteria)criteria
                                                       desc:(BOOL)desc;

- (nullable NSArray<VLCMLMedia *> *)searchMediaWithPattern:(NSString *)pattern;
- (nullable NSArray<VLCMLMedia *> *)searchMediaWithPattern:(NSString *)pattern
                                                     sort:(VLCMLSortingCriteria)criteria
                                                     desc:(BOOL)desc;

- (UInt32)nbSubscriptions;
- (UInt32)nbUnplayedMedia;
- (UInt32)nbMedia;

/**
 * @brief refresh Queues a refresh task for each subscription of this service.
 * @return YES if all the subscriptions were refreshed successfully
 */
- (BOOL)refresh;

@end

NS_ASSUME_NONNULL_END
