//
//  MKRWIFIRadioControlManager.m
//  MaoKRadioPlayer
//
//  Created by yyqxiaoyin on 2019/4/7.
//  Copyright © 2019 Muzen. All rights reserved.
//

#import "MKRWIFIRadioControlManager.h"
#import "MKRWIFIDeviceManager.h"
#import "MKRRadioResorce.h"

@interface MKRWIFIRadioControlManager ()

@end

@implementation MKRWIFIRadioControlManager

+ (instancetype)shareManager{
    static MKRWIFIRadioControlManager *manager = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        manager = [[MKRWIFIRadioControlManager alloc] init];
    });
    return manager;
}
#pragma mark - MKRPlayControlProtocol
- (id <MKRRadioResorce>)currentPlayingSong {
    return [[MKRWIFIDeviceManager shareManager] getPlayingStatusWithDevice:self.currentDevice];
}

#pragma mark - MKRPlayControlProtocol
- (void)play{
    [_MKRWIFIDeviceManager playWithDevice:self.currentDevice];
}

- (void)pause{
    [_MKRWIFIDeviceManager pauseWithDevice:self.currentDevice];
}

- (void)stop{
    [_MKRWIFIDeviceManager stopWithDevice:self.currentDevice];
}

- (void)next{
    [_MKRWIFIDeviceManager nextWithDevice:self.currentDevice];
}

- (void)previous{
    [_MKRWIFIDeviceManager previousWithDevice:self.currentDevice];
}

- (void)setVolume:(int)volume{
    [_MKRWIFIDeviceManager setVolume:volume device:self.currentDevice];
}

- (void)seekToTimeInterval:(NSTimeInterval)timeInterval{
    [_MKRWIFIDeviceManager seekToTimeInterval:timeInterval device:self.currentDevice];
}

- (void)playSongWithChannelNO:(NSString *)channelNO userID:(NSString *)userID {
    [_MKRWIFIDeviceManager playSongWithChannelNO:[channelNO integerValue]
                                          device:self.currentDevice
                                          userID:userID];
}

- (void)playSongWithChannelNO:(NSString *)channelNO index:(NSInteger)index userID:(NSString *)userID {
    [_MKRWIFIDeviceManager playSongWithChannelNO:[channelNO integerValue]
                                           index:index
                                          device:self.currentDevice
                                          userID:userID];
}

- (void)playTempSongs:(NSArray <id <MKRRadioResorce>> *)songs index:(NSInteger)index userID:(NSString *)userID {
    if (!songs.count) {
        [_MKRWIFIDeviceManager clearChannelWithChannelNO:@"12" device:self.currentDevice];
    }
    if (index >= songs.count) return;
//    NSString *channelID  = [NSString stringWithFormat:@"%@-%@-%@",[Userinfo ShareUser].uid,[_MKRRadioManager currentDev].devUUId,TempChannelUUID];
//    NSString *playModeStr = [[DevControlTools shareInstance].channelPlayModeList objectForKey:channelID];
//    NSArray *tempPlayList;
//    if([playModeStr isEqualToString:@"SHUFFLE"]){
//        tempPlayList = [CAPAllTools makeRandomArray:songs];
//    }else{
//        tempPlayList  = songs;
//    }
    MKRM3UListModel *m3uModel = [MKRM3UListModel tempChannelM3UModelWithSongs:songs startIndex:index];
    m3uModel.userID = @"";
    m3uModel.playModeString = @"";
    [[MKRWIFIDeviceManager shareManager] setM3UList:m3uModel];
    [_MKRWIFIDeviceManager setAVTransportURIWithSong:songs[index] device:self.currentDevice userID:@""];
    [_MKRWIFIDeviceManager playSongWithChannelNO:12 device:self.currentDevice userID:userID];
}

- (void)playTempSongs:(NSArray <id <MKRRadioResorce>> *)songs userID:(NSString *)userID {
    [self playTempSongs:songs index:0 userID:userID];
}

@end
