// --------------------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License. See License.txt in the project root for
// license information.
//
// Code generated by Microsoft (R) AutoRest Code Generator.
// Changes may cause incorrect behavior and will be lost if the code is
// regenerated.
// --------------------------------------------------------------------------

import AzureCore
import Foundation
// swiftlint:disable superfluous_disable_command
// swiftlint:disable identifier_name
// swiftlint:disable line_length
// swiftlint:disable cyclomatic_complexity

/// Identifies a participant in Azure Communication services. A participant is, for example, a phone number or an Azure
/// communication user. This model must be interpreted as a union: Apart from rawId, at most one further property may be
/// set.
internal struct CommunicationIdentifierModelInternal: Codable {
    // MARK: Properties

    /// Raw Id of the identifier. Optional in requests, required in responses.
    internal let rawId: String?
    /// The communication user.
    internal let communicationUser: CommunicationUserIdentifierModel?
    /// The phone number.
    internal let phoneNumber: PhoneNumberIdentifierModel?
    /// The Microsoft Teams user.
    internal let microsoftTeamsUser: MicrosoftTeamsUserIdentifierModel?

    // MARK: Initializers

    /// Initialize a `CommunicationIdentifierModelInternal` structure.
    /// - Parameters:
    ///   - rawId: Raw Id of the identifier. Optional in requests, required in responses.
    ///   - communicationUser: The communication user.
    ///   - phoneNumber: The phone number.
    ///   - microsoftTeamsUser: The Microsoft Teams user.
    internal init(
        rawId: String? = nil, communicationUser: CommunicationUserIdentifierModel? = nil,
        phoneNumber: PhoneNumberIdentifierModel? = nil, microsoftTeamsUser: MicrosoftTeamsUserIdentifierModel? = nil
    ) {
        self.rawId = rawId
        self.communicationUser = communicationUser
        self.phoneNumber = phoneNumber
        self.microsoftTeamsUser = microsoftTeamsUser
    }

    // MARK: Codable

    enum CodingKeys: String, CodingKey {
        case rawId = "rawId"
        case communicationUser = "communicationUser"
        case phoneNumber = "phoneNumber"
        case microsoftTeamsUser = "microsoftTeamsUser"
    }

    /// Initialize a `CommunicationIdentifierModelInternal` structure from decoder
    public init(from decoder: Decoder) throws {
        let container = try decoder.container(keyedBy: CodingKeys.self)
        self.rawId = try? container.decode(String.self, forKey: .rawId)
        self.communicationUser = try? container.decode(
            CommunicationUserIdentifierModel.self,
            forKey: .communicationUser
        )
        self.phoneNumber = try? container.decode(PhoneNumberIdentifierModel.self, forKey: .phoneNumber)
        self.microsoftTeamsUser = try? container.decode(
            MicrosoftTeamsUserIdentifierModel.self,
            forKey: .microsoftTeamsUser
        )
    }

    /// Encode a `CommunicationIdentifierModelInternal` structure
    public func encode(to encoder: Encoder) throws {
        var container = encoder.container(keyedBy: CodingKeys.self)
        if rawId != nil { try? container.encode(rawId, forKey: .rawId) }
        if communicationUser != nil { try? container.encode(communicationUser, forKey: .communicationUser) }
        if phoneNumber != nil { try? container.encode(phoneNumber, forKey: .phoneNumber) }
        if microsoftTeamsUser != nil { try? container.encode(microsoftTeamsUser, forKey: .microsoftTeamsUser) }
    }
}
