/*****************************************************************************
 * VLCMLSubscription.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>
#import "VLCMLObject.h"
#import "VLCMLService.h"

typedef NS_ENUM(NSUInteger, VLCMLSortingCriteria);

@class VLCMLMedia;

NS_ASSUME_NONNULL_BEGIN

/**
 * @brief The VLCMLSubscription class represents a collection of media imported
 * from a service, such as a single podcast feed.
 */
@interface VLCMLSubscription : NSObject <VLCMLObject>

@property (nonatomic, copy, readonly) NSString *name;

/**
 * @brief artworkMRL The subscription's artwork MRL, or nil if none is available.
 */
@property (nonatomic, copy, readonly, nullable) NSURL *artworkMRL;

/**
 * @brief maxCachedMedia The maximum number of cached media for this
 * subscription, or -1 if unset (inherit the service/global setting).
 *
 * Set to a negative value to erase this subscription's setting and inherit
 * again.
 */
@property (nonatomic) SInt32 maxCachedMedia;

/**
 * @brief maxCacheSize The maximum cache size in bytes for this subscription,
 * or -1 if unset (inherit the service/global setting).
 */
@property (nonatomic) SInt64 maxCacheSize;

/**
 * @brief newMediaNotification The new-media notification setting.
 *
 * A positive value if explicitly enabled, 0 if explicitly disabled, -1 if unset
 * (in which case the parent service setting is used). Assign accordingly.
 */
@property (nonatomic) SInt8 newMediaNotification;

- (instancetype)init NS_UNAVAILABLE;

- (VLCMLIdentifier)identifier;

/**
 * @brief serviceType The type of the service this subscription belongs to.
 */
- (VLCMLServiceType)serviceType;

/**
 * @brief childSubscriptions The child subscriptions of this subscription.
 *
 * @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 *> *)childSubscriptions;
- (nullable NSArray<VLCMLSubscription *> *)childSubscriptionsWithSortingCriteria:(VLCMLSortingCriteria)criteria
                                                                          desc:(BOOL)desc;

/**
 * @brief parent The parent subscription, or nil if this is a top-level one.
 */
- (nullable VLCMLSubscription *)parent;

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

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

/**
 * @brief refresh Queues a refresh task for this subscription.
 * @return YES if the refresh was queued successfully
 */
- (BOOL)refresh;

/**
 * @brief cachedSize The sum in bytes of all cached files for this subscription.
 */
- (UInt64)cachedSize;

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

@end

NS_ASSUME_NONNULL_END
