//
//  PUPlayOptionsManager.m
//  BJPlayerManagerUI_Example
//
//  Created by HuangJie on 2018/6/5.
//  Copyright © 2018年 oushizishu. All rights reserved.
//

#import <BJLiveBase/BJLiveBase+UIKit.h>
#import <BJLiveBase/BJLYYModel.h>

#import "PUPlayOptionsManager.h"

static NSString * const videoOptionsKey = @"video_options";
static NSString * const playbackOptionsKey = @"playback_options";
static NSString * const privatePrefixKey = @"private_prefix";

@implementation PUPlayOptionsManager

#pragma mark - BJPUVideoOptions 点播设置

+ (void)setVideoOptions:(BJPUVideoOptions *)videoOptions {
    id jsonObject = [videoOptions bjlyy_modelToJSONObject];
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    [userDefaults setObject:jsonObject forKey:videoOptionsKey];
    [userDefaults synchronize];
}

+ (BJPUVideoOptions *)getVideoOptions {
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    id jsonObject = [userDefaults objectForKey:videoOptionsKey];
    return [BJPUVideoOptions bjlyy_modelWithJSON:jsonObject] ?: [BJPUVideoOptions new];
}

#pragma mark - BJPPlaybackOptions 回放设置

+ (void)setPlaybackOptions:(BJPPlaybackOptions *)playbackOptions {
    id jsonObject = [playbackOptions bjlyy_modelToJSONObject];
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    [userDefaults setObject:jsonObject forKey:playbackOptionsKey];
    [userDefaults synchronize];
}

+ (BJPPlaybackOptions *)getPlaybackOptions {
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    id jsonObject = [userDefaults objectForKey:playbackOptionsKey];
    return [BJPPlaybackOptions bjlyy_modelWithJSON:jsonObject] ?: [BJPPlaybackOptions new];
}

#pragma mark - 专属域名

+ (void)setPrivatePrefix:(NSString *)privatePrefix {
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    [userDefaults setObject:privatePrefix forKey:privatePrefixKey];
    [userDefaults synchronize];
}

+ (NSString *)getPrivatePrefix {
    NSUserDefaults *userDefaults = [NSUserDefaults standardUserDefaults];
    return [userDefaults stringForKey:privatePrefixKey];
}

@end
