//
//  Copyright (c) 2020 gematik GmbH
//  
//  Licensed under the Apache License, Version 2.0 (the "License");
//  you may not use this file except in compliance with the License.
//  You may obtain a copy of the License at
//  
//     http://www.apache.org/licenses/LICENSE-2.0
//  
//  Unless required by applicable law or agreed to in writing, software
//  distributed under the License is distributed on an "AS IS" BASIS,
//  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
//  See the License for the specific language governing permissions and
//  limitations under the License.
//

//
//  This file was generated from an xsd file and represents a simple or complex type of it.
//  Generated by a fork of xsd2cocoa (see https://github.com/Daij-Djan/xsd2cocoa) and a specified custom transform template.
//

import Foundation
import XMLTools

// MARK: - Generated file, do not edit. Any edits of this file will be overwritten and thus discarded.
public class NFD_NFD_Behandelnder_Arzt_Institution {
    
    public static let namespacePrefix: String? = "NFD"
    public static let namespaceUri: String? = "http://ws.gematik.de/fa/nfds/NFD_Document/v1.4"
    
    // attributes:
    public var BAI_Art: String
    
    // elements:
    public var NFD_BAI_Arzt_Nachname: String
    public var NFD_BAI_Arzt_Vorname: String?
    public var NFD_BAI_Institution_Bezeichnung: String?
    public var NFD_BAI_Arzt_Bezeichnung: String?
    public var NFD_BAI_Adresse: NFD_NFD_Adresse?
    public var NFD_BAI_Kommunikation: [NFD_NFD_Kommunikationsdaten]
    
    // default Constructor
    public init() {
        
        self.BAI_Art = String()
        
        self.NFD_BAI_Arzt_Nachname = String()
        self.NFD_BAI_Arzt_Vorname = nil
        self.NFD_BAI_Institution_Bezeichnung = nil
        self.NFD_BAI_Arzt_Bezeichnung = nil
        self.NFD_BAI_Adresse = nil
        self.NFD_BAI_Kommunikation = [NFD_NFD_Kommunikationsdaten]()
        
    }
    
    // copy Constructor
    public init(_ _NFD_NFD_Behandelnder_Arzt_Institution: NFD_NFD_Behandelnder_Arzt_Institution ) {
        
        self.BAI_Art = _NFD_NFD_Behandelnder_Arzt_Institution.BAI_Art
        
        self.NFD_BAI_Arzt_Nachname = _NFD_NFD_Behandelnder_Arzt_Institution.NFD_BAI_Arzt_Nachname
        self.NFD_BAI_Arzt_Vorname = _NFD_NFD_Behandelnder_Arzt_Institution.NFD_BAI_Arzt_Vorname
        self.NFD_BAI_Institution_Bezeichnung = _NFD_NFD_Behandelnder_Arzt_Institution.NFD_BAI_Institution_Bezeichnung
        self.NFD_BAI_Arzt_Bezeichnung = _NFD_NFD_Behandelnder_Arzt_Institution.NFD_BAI_Arzt_Bezeichnung
        self.NFD_BAI_Adresse = _NFD_NFD_Behandelnder_Arzt_Institution.NFD_BAI_Adresse
        self.NFD_BAI_Kommunikation = _NFD_NFD_Behandelnder_Arzt_Institution.NFD_BAI_Kommunikation
        
    }
    
    public class func deserialize(_ infoset: Infoset) -> NFD_NFD_Behandelnder_Arzt_Institution {
        
        let _NFD_NFD_Behandelnder_Arzt_Institution = NFD_NFD_Behandelnder_Arzt_Institution()
        
        _NFD_NFD_Behandelnder_Arzt_Institution.BAI_Art = String.deserialize(infoset.attr("BAI_Art"))
        
        let uriNFD_BAI_Arzt_Nachname = String.namespaceUri ?? self.namespaceUri ?? infoset.namespaceContext.defaultURI!
        let qNameNFD_BAI_Arzt_Nachname = QName("NFD_BAI_Arzt_Nachname", uri: uriNFD_BAI_Arzt_Nachname)
        _NFD_NFD_Behandelnder_Arzt_Institution.NFD_BAI_Arzt_Nachname = String.deserialize(infoset.select(qNameNFD_BAI_Arzt_Nachname))
        
        let uriNFD_BAI_Arzt_Vorname = String.namespaceUri ?? self.namespaceUri ?? infoset.namespaceContext.defaultURI!
        let qNameNFD_BAI_Arzt_Vorname = QName("NFD_BAI_Arzt_Vorname", uri: uriNFD_BAI_Arzt_Vorname)
        _NFD_NFD_Behandelnder_Arzt_Institution.NFD_BAI_Arzt_Vorname = String?.deserialize(infoset.select(qNameNFD_BAI_Arzt_Vorname))
        
        let uriNFD_BAI_Institution_Bezeichnung = String.namespaceUri ?? self.namespaceUri ?? infoset.namespaceContext.defaultURI!
        let qNameNFD_BAI_Institution_Bezeichnung = QName("NFD_BAI_Institution_Bezeichnung", uri: uriNFD_BAI_Institution_Bezeichnung)
        _NFD_NFD_Behandelnder_Arzt_Institution.NFD_BAI_Institution_Bezeichnung = String?.deserialize(infoset.select(qNameNFD_BAI_Institution_Bezeichnung))
        
        let uriNFD_BAI_Arzt_Bezeichnung = String.namespaceUri ?? self.namespaceUri ?? infoset.namespaceContext.defaultURI!
        let qNameNFD_BAI_Arzt_Bezeichnung = QName("NFD_BAI_Arzt_Bezeichnung", uri: uriNFD_BAI_Arzt_Bezeichnung)
        _NFD_NFD_Behandelnder_Arzt_Institution.NFD_BAI_Arzt_Bezeichnung = String?.deserialize(infoset.select(qNameNFD_BAI_Arzt_Bezeichnung))
        
        let uriNFD_BAI_Adresse = NFD_NFD_Adresse.namespaceUri ?? self.namespaceUri ?? infoset.namespaceContext.defaultURI!
        let qNameNFD_BAI_Adresse = QName("NFD_BAI_Adresse", uri: uriNFD_BAI_Adresse)
        _NFD_NFD_Behandelnder_Arzt_Institution.NFD_BAI_Adresse = NFD_NFD_Adresse?.deserialize(infoset.select(qNameNFD_BAI_Adresse))
        
        let uriNFD_BAI_Kommunikation = [NFD_NFD_Kommunikationsdaten]().namespaceUri ?? self.namespaceUri ?? infoset.namespaceContext.defaultURI!
        let qNameNFD_BAI_Kommunikation = QName("NFD_BAI_Kommunikation", uri: uriNFD_BAI_Kommunikation)
        _NFD_NFD_Behandelnder_Arzt_Institution.NFD_BAI_Kommunikation = [NFD_NFD_Kommunikationsdaten].deserialize(infoset.select(qNameNFD_BAI_Kommunikation))
        
        return _NFD_NFD_Behandelnder_Arzt_Institution
    }
}

extension Optional where Wrapped == NFD_NFD_Behandelnder_Arzt_Institution {
    public static func deserialize(_ infoset: Infoset) -> NFD_NFD_Behandelnder_Arzt_Institution? {
        if infoset.count == 0 {
            return nil
        } else {
            return NFD_NFD_Behandelnder_Arzt_Institution.deserialize(infoset)
        }
    }
}

extension Array where Element: NFD_NFD_Behandelnder_Arzt_Institution {
    public var namespaceUri: String? {
        get {
            return NFD_NFD_Behandelnder_Arzt_Institution.namespaceUri
        }
    }
    
    public static func deserialize(_ infoset: Infoset) -> [NFD_NFD_Behandelnder_Arzt_Institution] {
        return infoset.map { (element: Infoset) in
        NFD_NFD_Behandelnder_Arzt_Institution.deserialize(element)
    }
}
}

// utility functions
fileprivate extension String {
    static let namespacePrefix: String? = nil
    static let namespaceUri: String? = nil
    
    static func deserialize(_ infoset: Infoset) -> String {
        return infoset.text
    }
}

fileprivate extension Optional where Wrapped == String {
    static func deserialize(_ infoset: Infoset) -> String? {
        if infoset.count == 0 {
            return nil
        } else {
            return String.deserialize(infoset)
        }
    }
}

fileprivate extension Int {
    static let namespacePrefix: String? = nil
    static let namespaceUri: String? = nil
    
    static func deserialize(_ infoset: Infoset) -> Int {
        guard let ret = Int(infoset.text) else {
            return 0
        }
        return ret
    }
}

fileprivate extension Optional where Wrapped == Int {
    static func deserialize(_ infoset: Infoset) -> Int? {
        if infoset.count == 0 {
            return nil
        } else {
            return Int.deserialize(infoset)
        }
    }
}

fileprivate extension Double {
    static let namespacePrefix: String? = nil
    static let namespaceUri: String? = nil
    
    static func deserialize(_ infoset: Infoset) -> Double {
        guard let ret = Double(infoset.text) else {
            return 0
        }
        return ret
    }
}

fileprivate extension Optional where Wrapped == Double {
    static func deserialize(_ infoset: Infoset) -> Double? {
        if infoset.count == 0 {
            return nil
        } else {
            return Double.deserialize(infoset)
        }
    }
}

