//
//  Notification.swift
//  MusicPlayer
//
//  Created by Mr.Zhou on 2024/4/1.
//

import Foundation
///通知关键词协议
protocol NotificationKey {
    associatedtype Keys: RawRepresentable
}
///将RawValue转化为字符串
extension NotificationKey where Keys.RawValue == String {
    ///发通知
    static func post(notificationName key:Keys, object:Any? = nil) {
        let rawValue = key.rawValue
        NotificationCenter.default.post(name: NSNotification.Name(rawValue), object: object)
    }
    ///监听通知
    static func add(observer: AnyObject, selector: Selector, notificationName key: Keys, object:Any? = nil) {
        let rawValue = key.rawValue
        NotificationCenter.default.addObserver(observer, selector: selector, name: NSNotification.Name(rawValue), object: object)
    }
    ///移除通知
    static func remove(observer: AnyObject, notificationName key: Keys, object:Any? = nil) {
        let rawValue = key.rawValue
        NotificationCenter.default.removeObserver(observer, name: NSNotification.Name(rawValue), object: object)
    }
}
//MARK: - 扩写通知
extension NotificationCenter{
    struct notificationKey:NotificationKey {
        ///关键词
        enum Keys:String {
            ///切换taBarItem
            case switch_tabBarItem
            //MARK: - A面通知内容
            ///A面倒计时过程（携带时间值）
            case sideA_time_times
            ///A面音量值改变
            case sideA_volume_change
            ///A面启动音乐播放器
            case sideA_play_music
            ///A面终止音乐播放器与倒计时
            case sideA_stop_music
            ///A面暂停音乐播放器
            case sideA_pause_music
            ///A面继续音乐播放器
            case sideA_resume_music
            ///A面开启麦克风监听
            case sideA_open_monitor
            ///A面关闭麦克风监听
            case sideA_stop_monitor
            ///A面新增音乐选择页
            case sideA_new_choice
            ///A面音乐创建成功
            case sideA_creat_music
            ///A面音乐实体为空
            case sideA_null_music
            ///A面收起音乐展示框
            case sideA_close_show
            ///A面显示音乐展示框
            case sideA_display_show
            ///A面隐藏音乐展示框
            case sideA_hidden_show
            ///A面音乐实体重命名
            case sideA_rename_music
            //MARK: - b面通知内容
            ///JS代码注入完成
            case js_edit_completion
            ///预览数据已更新
            case positive_browses_reload
            ///播放器状态变化
            case switch_player_status
            ///弹出底部音乐模块
            case pup_bottom_show
            ///弹出音乐播放器
            case pup_player_vc
            ///播放器页面更新
            case positive_player_reload
            ///用户切换播放器播放方式
            case player_type_switch
            ///用户清空了歌单
            case player_delete_list
            ///网络状态切换-网络不可用
            case net_switch_notReachable
            ///网络状态切换-网络可用
            case net_switch_reachable
        }
    }
}
