/*
 Copyright (c) 2020 Swift Models Generated from JSON powered by http://www.json4swift.com

 Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

 The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

 For support, please feel free to contact me at https://www.linkedin.com/in/syedabsar

 */

import Foundation
import ObjectMapper
import RealmSwift
import BFCommonKit

public class PQEditSectionTimelineModel: PQEditBaseModel {
    @objc dynamic public var audioTrack: PQEditAudioTrackModel?
    @objc dynamic public var visionTrack: PQEditVisionTrackModel?

    required convenience public init?(map _: Map) {
        self.init()
    }

    required public init() {
        super.init()
        audioTrack = PQEditAudioTrackModel()
        visionTrack = PQEditVisionTrackModel()
    }

    public  override func mapping(map: Map) {
        audioTrack <- map["audioTrack"]
        visionTrack <- map["visionTrack"]
    }

    // 添加发声音人数据
   public  func addVoice(audioMix: PQVoiceModel) {
        deleteVoice()
        BFLog(message: "添加发声音人数据 \(audioMix.voice)")
        let audioTrackMaterial = PQEditAudioTrackMaterialModel()

        audioTrackMaterial.voiceType = VOICETYPT.PRODUCE.rawValue
        audioTrackMaterial.type = "voice"
        audioTrackMaterial.volumeGain = Float64(audioMix.volume)
        audioTrackMaterial.duration = audioMix.wavfileDuration

        let produceVoiceConfig = PQEditProduceVoiceConfigModel()
        produceVoiceConfig.channel = audioMix.channel
        //这里区分不同渠道 设置不同的参数语速和语调
        if produceVoiceConfig.channel == "aliyun" {
            produceVoiceConfig.pitchRate = Int(audioMix.pitchRate)
            produceVoiceConfig.speechRate = Int(audioMix.speedRate)
        } else {
            produceVoiceConfig.azurePitchRate = "\(audioMix.pitchRate)%"
            produceVoiceConfig.azureSpeechRate = "\(audioMix.speedRate)"
            produceVoiceConfig.azureStyle = audioMix.azureStyle
        }
        produceVoiceConfig.voice = audioMix.voice
        produceVoiceConfig.volume = audioMix.volume
        audioTrackMaterial.produceVoiceConfig = produceVoiceConfig

        audioTrack?.audioTrackMaterials.append(audioTrackMaterial)
    }

    // 删除发声音人，目前只有一个，配音
   public  func deleteVoice() {
        BFLog(message: "删除一个发声音人")
        audioTrack?.audioTrackMaterials.removeAll()
    }
}
