//
//  LKFContextDataRecordTypeLine.swift
//  LKF
//
//  Created by Alexander Holzer on 06.04.23.
//  Copyright © 2023 Alexander Holzer. All rights reserved.
//

import Foundation

public class LKFContextDataRecordTypeLine {
    public let type : String
    public var _line : String?
    public var _lkfLine: LKFLine?
    public let lineIdent: String
    
    public init (lineIdent: String, line: String, type: String? = nil) {
        self.type = type ?? String(line.prefix(3))
        self._line = line
        self.lineIdent = lineIdent
    }
    
    public init (lkfLine: LKFLine, type: String? = nil) {
        self.type = type ?? String(lkfLine.valueAt(index: 0))
        self._lkfLine = lkfLine
        self.lineIdent = lkfLine.lineIdent
    }
    
    public var line : String {
        if let _line {
            return _line
        }
        if let _line = _lkfLine?.line {
            self._line = _line
            return _line
        }
        return ""
    }
    
    public var lkfLine: LKFLine? {
        
        if let _lkfLine {
            return _lkfLine
        }
        if let _line {
            let lkfLine = LKFLine (_line, lineIdent: lineIdent)
            _lkfLine = lkfLine
            return lkfLine
        }
        return nil
    }
    
    open func with(line: String) -> LKFContextDataRecordTypeLine {
        return LKFContextDataRecordTypeLine(lineIdent: lineIdent, line: line, type: type)
    }
}

public class LKFContextDataRecordTypeAufenthaltLine : LKFContextDataRecordTypeLine {
    public let aufenthalt : LKFAufenthalt
    
    init (lineIdent: String, aufenthalt: LKFAufenthalt, line: String, type: String? = nil) {
        self.aufenthalt = aufenthalt
        super.init(lineIdent: lineIdent, line: line, type: type)
    }
    
    override open func with(line: String) -> LKFContextDataRecordTypeLine {
        return LKFContextDataRecordTypeAufenthaltLine(lineIdent: lineIdent, aufenthalt: aufenthalt, line: line, type: type)
    }
}
