//
//  VenueInvite.swift
//  OrdermentumSDK
//
//  Created by Brandon Stillitano on 18/3/19.
//  Copyright © 2019 Ordermentum Pty Ltd. All rights reserved.
//

import Foundation

public struct VenueInviteResponse {
    public var data: [VenueInvite] = []
}

public struct VenueInvite {
    public init() {}

    public var createdByName: String = ""
    public var id: String = ""
    public var recipientEntityName: String = ""
    public var senderEntityName: String = ""
    public var supplierSender: Supplier = Supplier()
    public var retailerRecipient: Retailer = Retailer()
    public var mergeable: Bool = false
}

extension VenueInviteResponse: Decodable {
    public init(from decoder: Decoder) throws {
        //Create Container
        guard let container = try? decoder.container(keyedBy: CodingKeys.self) else {
            return
        }

        data = container.tryDecode(type: [VenueInvite].self, forKey: .data) ?? []
    }
}

extension VenueInvite: Decodable {
    public init(from decoder: Decoder) throws {
        //Create Container
        guard let container = try? decoder.container(keyedBy: CodingKeys.self) else {
            return
        }
        
        id = container.tryDecode(type: String.self, forKey: .id) ?? ""
        senderEntityName = container.tryDecode(type: String.self, forKey: .senderEntityName) ?? ""
        recipientEntityName = container.tryDecode(type: String.self, forKey: .recipientEntityName) ?? ""
        createdByName = container.tryDecode(type: String.self, forKey: .createdByName) ?? ""
        supplierSender = container.tryDecode(type: Supplier.self, forKey: .supplierSender) ?? Supplier()
        retailerRecipient = container.tryDecode(type: Retailer.self, forKey: .retailerRecipient) ?? Retailer()
        mergeable = container.tryDecode(type: Bool.self, forKey: .mergeable) ?? false
    }
}
