// --------------------------------------------------------------------------
// 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

/// Summary information of a chat thread.
public struct ChatThreadItem: Codable {
    // MARK: Properties

    /// Chat thread id.
    public let id: String
    /// Chat thread topic.
    public let topic: String
    /// The timestamp when the chat thread was deleted. The timestamp is in RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`.
    public let deletedOn: Iso8601Date?
    /// The timestamp when the last message arrived at the server. The timestamp is in RFC3339 format:
    /// `yyyy-MM-ddTHH:mm:ssZ`.
    public let lastMessageReceivedOn: Iso8601Date?

    // MARK: Initializers

    /// Initialize a `ChatThreadItem` structure.
    /// - Parameters:
    ///   - id: Chat thread id.
    ///   - topic: Chat thread topic.
    ///   - deletedOn: The timestamp when the chat thread was deleted. The timestamp is in RFC3339 format:
    /// `yyyy-MM-ddTHH:mm:ssZ`.
    ///   - lastMessageReceivedOn: The timestamp when the last message arrived at the server. The timestamp is in
    /// RFC3339 format: `yyyy-MM-ddTHH:mm:ssZ`.
    public init(
        id: String, topic: String, deletedOn: Iso8601Date? = nil, lastMessageReceivedOn: Iso8601Date? = nil
    ) {
        self.id = id
        self.topic = topic
        self.deletedOn = deletedOn
        self.lastMessageReceivedOn = lastMessageReceivedOn
    }

    // MARK: Codable

    enum CodingKeys: String, CodingKey {
        case id = "id"
        case topic = "topic"
        case deletedOn = "deletedOn"
        case lastMessageReceivedOn = "lastMessageReceivedOn"
    }

    /// Initialize a `ChatThreadItem` structure from decoder
    public init(from decoder: Decoder) throws {
        let container = try decoder.container(keyedBy: CodingKeys.self)
        self.id = try container.decode(String.self, forKey: .id)
        self.topic = try container.decode(String.self, forKey: .topic)
        self.deletedOn = try? container.decode(Iso8601Date.self, forKey: .deletedOn)
        self.lastMessageReceivedOn = try? container.decode(Iso8601Date.self, forKey: .lastMessageReceivedOn)
    }

    /// Encode a `ChatThreadItem` structure
    public func encode(to encoder: Encoder) throws {
        var container = encoder.container(keyedBy: CodingKeys.self)
        try container.encode(id, forKey: .id)
        try container.encode(topic, forKey: .topic)
        if deletedOn != nil { try? container.encode(deletedOn, forKey: .deletedOn) }
        if lastMessageReceivedOn != nil { try? container.encode(lastMessageReceivedOn, forKey: .lastMessageReceivedOn) }
    }
}
