//
//  LKFContextDataRecordType.swift
//  lkfc
//
//  Created by Alexander Holzer on 06.04.23.
//  Copyright © 2023 Alexander Holzer. All rights reserved.
//

import Foundation

public class LKFContextDataRecordType {
    public let type: String
    public private(set) var lines : [LKFContextDataRecordTypeLine]
    
    public init (type: String, line: LKFContextDataRecordTypeLine? = nil) {
        self.type = type
        if let line {
            lines = [line]
        }
        else {
            lines = []
        }
    }
    
    public func replace (line: LKFContextDataRecordTypeLine, at index: Int) {
        self.lines[index] = line
    }
    
    func add (line: LKFContextDataRecordTypeLine) {
        lines.append(line)
    }
    
    public func getMaxColumnCount() -> Int {
        var columnCount = 0
        for line in lines {
            let partCount = line.line.components(separatedBy: "|")
            if partCount.count > columnCount {
                columnCount = partCount.count
            }
        }
        return columnCount
    }
}
