//
// © 2018-2020 Qualcomm Technologies, Inc. and/or its subsidiaries. All rights reserved.
//

#import <Foundation/Foundation.h>
#import "IoTPlayer.h"
#import "IoTTypes.h"

@class IoTAllPlayController;
@class IoTMediaItem;
@class IoTPlaylist;
@class IoTPlayerGroupsInfo;

NS_ASSUME_NONNULL_BEGIN

@protocol IoTPlayerUpdates <NSObject>

- (void)player:(IoTPlayer *)player didHavePlaybackError:(NSError *)error atIndex:(NSUInteger)index;
- (void)playerDidChangeEnabledControls:(IoTPlayer *)player;
- (void)playerDidChangePlaylist:(IoTPlayer *)player;
- (void)playerDidChangeAudioConfiguration:(IoTPlayer *)player;
- (void)player:(IoTPlayer *)player didChangeLoopMode:(IoTLoopMode)loopMode;
- (void)player:(IoTPlayer *)player didChangeShuffleMode:(IoTShuffleMode)shuffleMode;
- (void)player:(IoTPlayer *)player didChangePlayState:(IoTPlayState)state;
- (void)player:(IoTPlayer *)player didChangeDisplayName:(NSString *)name;
- (void)player:(IoTPlayer *)player didChangeVolume:(double)volume;
- (void)player:(IoTPlayer *)player didChangeGroupVolume:(double)volume;
- (void)player:(IoTPlayer *)player didChangeMuteState:(BOOL)muted;
- (void)player:(IoTPlayer *)player didChangeGroupMuteState:(BOOL)muted;
- (void)playerDidChangeGroupInfo:(IoTPlayer *)player;
- (void)playerDidChangeLeadPlayer:(IoTPlayer *)player;
- (void)player:(IoTPlayer *)player didChangeInputSelector:(IoTInputOutputSelector *)inputSelector;
- (void)player:(IoTPlayer *)player didChangeOutputSelectors:(NSArray<IoTInputOutputSelector *> *)outputSelectors;
- (void)player:(IoTPlayer *)player homeTheaterChannelAvailabilityChanged:(IoTHomeTheaterChannel)channel;
- (void)player:(IoTPlayer *)player homeTheaterChannelVolumeChanged:(IoTHomeTheaterChannel)channel;

@end

@interface IoTPlayer (Private)

- (instancetype)initWithAllPlayController:(IoTAllPlayController *)allPlayController
                          applicationName:(NSString *)appName
                           stateSyncQueue:(dispatch_queue_t)syncQueue;

- (void)updateWithCompletion:(nullable void(^)(BOOL))completion
             completionQueue:(nullable dispatch_queue_t)queue;

- (void)replaceAllPlayController:(IoTAllPlayController *)allPlayController;

@property (nonatomic, weak) id<IoTPlayerUpdates> updatesDelegate;

- (NSString *)host;
- (NSString *)leadPlayerInGroupID;
- (NSString *)appID;
- (NSString *)groupID;

- (nullable IoTPlayerGroupsInfo *)groupsInfo;

// - (int apiVersion;

- (BOOL)isAudioSupported;
- (BOOL)isVideoSupported;
- (BOOL)isPhotoSupported;

@end

@interface IoTPlayer (PlayerGroup)

- (BOOL)isMasterVolumeSupported;

@property (readonly, assign) double masterVolume;
@property (readonly, assign) double masterMaxVolume;
@property (readonly, assign) BOOL isMasterVolumeMuted;

- (void)setMasterVolume:(double)volume
             completion:(nullable IoTCompletionHandler)completion
        completionQueue:(nullable dispatch_queue_t)queue;

- (void)setMasterMuted:(BOOL)mute
            completion:(nullable IoTCompletionHandler)completion
       completionQueue:(nullable dispatch_queue_t)queue;

- (IoTPlayState)playState;
- (int)playerPosition;

- (BOOL)isSeekEnabled;
- (BOOL)isPreviousEnabled;
- (BOOL)isNextEnabled;
- (BOOL)isPauseEnabled;

- (void)setPlayerPosition:(int)position
               completion:(nullable IoTCompletionHandler)completion
          completionQueue:(nullable dispatch_queue_t)queue;

- (void)playWithCompletion:(nullable IoTCompletionHandler)completion
           completionQueue:(nullable dispatch_queue_t)queue;

- (void)playMediaItem:(IoTMediaItem *)mediaItem
           completion:(nullable IoTCompletionHandler)completion
      completionQueue:(nullable dispatch_queue_t)queue;

- (void)pauseWithCompletion:(nullable IoTCompletionHandler)completion
            completionQueue:(nullable dispatch_queue_t)queue;

- (void)stopWithCompletion:(nullable IoTCompletionHandler)completion
           completionQueue:(nullable dispatch_queue_t)queue;

- (void)nextWithCompletion:(nullable IoTCompletionHandler)completion
           completionQueue:(nullable dispatch_queue_t)queue;

- (void)previousWithCompletion:(nullable IoTCompletionHandler)completion
               completionQueue:(nullable dispatch_queue_t)queue;

- (void)playItemAtIndex:(int)index
             completion:(nullable IoTCompletionHandler)completion
        completionQueue:(nullable dispatch_queue_t)queue;

- (void)createPlayerGroupWithName:(NSString *)name
                       completion:(void(^)(BOOL success, NSString * _Nullable groupID, NSError * _Nullable error))completion
                  completionQueue:(nullable dispatch_queue_t)queue;

- (void)renamePlayerGroupWithID:(NSString *)groupID
                        newName:(NSString *)newName
                     completion:(nullable IoTCompletionHandler)completion
                completionQueue:(nullable dispatch_queue_t)queue;

- (void)deletePlayerGroupWithID:(NSString *)groupID
                     completion:(nullable IoTCompletionHandler)completion
                completionQueue:(nullable dispatch_queue_t)queue;

- (void)addToPlayerGroupWithID:(NSString *)groupID
                    completion:(nullable IoTCompletionHandler)completion
               completionQueue:(nullable dispatch_queue_t)queue;

- (void)removeFromPlayerGroupWithCompletion:(nullable IoTCompletionHandler)completion
                            completionQueue:(nullable dispatch_queue_t)queue;

@end

@interface IoTPlayer (Playlist)

- (BOOL)isLoopModeEnabled;
- (BOOL)isShuffleModeEnabled;
- (IoTLoopMode)loopMode;
- (IoTShuffleMode)shuffleMode;

- (void)setLoopMode:(IoTLoopMode)loopMode
         completion:(nullable IoTCompletionHandler)completion
    completionQueue:(nullable dispatch_queue_t)queue;

- (void)setShuffleMode:(IoTShuffleMode)shuffleMode
            completion:(nullable IoTCompletionHandler)completion
       completionQueue:(nullable dispatch_queue_t)queue;

- (IoTMediaItem *)currentItem;
- (int)indexPlaying;

- (BOOL)isPlaylistInterfaceSupported;
- (NSString *)playlistSnapshotID;
- (NSString *)playlistControllerType;
- (NSString *)playlistUserData;
- (uint)playlistSize;

- (void)addMediaItem:(IoTMediaItem *)mediaItem
             atIndex:(int)index
                play:(BOOL)play
            userData:(NSString *)userData
          completion:(nullable IoTCompletionHandler)completion
     completionQueue:(nullable dispatch_queue_t)queue;

- (void)addMediaItems:(NSArray *)mediaItems
              atIndex:(int)index
                 play:(BOOL)play
             userData:(NSString *)userData
           completion:(nullable IoTCompletionHandler)completion
      completionQueue:(nullable dispatch_queue_t)queue;

- (void)removeMediaItemsInRange:(NSRange)range
                     completion:(nullable IoTCompletionHandler)completion
                completionQueue:(nullable dispatch_queue_t)queue;

- (void)moveMediaItemsInRange:(NSRange)range
                     position:(int)position
                   completion:(nullable IoTCompletionHandler)completion
              completionQueue:(nullable dispatch_queue_t)queue;

- (void)clearWithCompletion:(nullable IoTCompletionHandler)completion
            completionQueue:(nullable dispatch_queue_t)queue;

- (void)getItemsInRange:(NSRange)range
             completion:(nullable void(^)(BOOL success, NSArray<IoTMediaItem *> *items,NSError * _Nullable error))completion
        completionQueue:(nullable dispatch_queue_t)queue;

@end

// Home Theater

@interface IoTPlayer (HomeTheater)

- (void)updateHomeTheaterRatioVolumesForPlayerVolume:(double)volume
                                          completion:(nullable IoTCompletionHandler)completion
                                     completionQueue:(nullable dispatch_queue_t)queue;

- (NSArray<NSString *> *)allRemovableHomeTheaterPlayerIDs;

@end

NS_ASSUME_NONNULL_END
