//
//  LKFScoringDetailsAbt.swift
//  LKF
//
//  Created by Alexander Holzer on 26.02.22.
//  Copyright © 2022 Alexander Holzer. All rights reserved.
//

import Foundation

public class LKFScoringDetailsAbt : Identifiable {
    
    public let id: String
    
    public let parts : [String]
    public let abt: LKFAufenthaltAbt
    public let abtIndex: UInt32
    public let mels: [LKFScoringDetailsMEL]
    
    init (aufenthalt:LKFAufenthalt, abtIndex: UInt32, mels:[LKFScoringDetailsMEL], line: String) {
        self.parts = line.components(separatedBy: "|")
        self.abtIndex = abtIndex
        self.id = "\(aufenthalt.key)-\(abtIndex)"
        self.mels = mels
        self.abt = aufenthalt.abtAt(index: abtIndex)
    }
    
    public var spezBereich : String {
        return parts.count > 1 ? parts[1] : ""
    }
    
    public var days : Int {
        return Int(parts[0]) ?? 0
    }
    
    public var lp100: Int {
        return parts.count > 3 ? (Int(parts[3]) ?? 0) : 0
    }
    
    public var tp100: Int {
        return parts.count > 4 ? (Int(parts[4]) ?? 0) : 0
    }
    
    public var spezPoints : Int {
        return parts.count > 2 ? (Int(parts[2]) ?? 0) : 0
    }

    
    public var traceLine : String {
        let spezBereich = self.spezBereich
        
        var s = "\(abt.POS) - \(abt.ABTFC): vw=\(days)"
        
        if spezBereich.count > 0 {
            s += ", \(spezBereich) (\(spezPoints))"
        }
        if tp100 > 0 {
            s += ", TP100=\(tp100)"
        }
        if lp100 > 0 {
            s += ", LP100=\(lp100)"
        }
        
        return s
    }

}
