//
//  LKFStat.swift
//  lkfc
//
//  Created by Alexander Holzer on 01.12.19.
//  Copyright © 2019 Alexander Holzer. All rights reserved.
//

import Foundation
@_implementationOnly import LibLKF

public enum LKFAmbStatValue : UInt32 {
    case Chemo = 0
    case Psych = 1
    case ZAE = 2
    case TKL = 3
    case AbtFC = 10
}

public class LKFStat {
    
    let context : LKFContext
    
    init (context: LKFContext) {
        self.context = context
    }
    
    func GetAmbValue (statValue: LKFAmbStatValue) -> Int
    {
        if let ptr = context.ptr {
            return Int (LibLKF.lkf_get_amb_counter(ptr, statValue.rawValue))
        }
        return 0
    }
    
    func GetAmbKostenstelleCount () -> UInt32 {
        if let ptr = context.ptr {
            return LibLKF.lkf_get_amb_kostenstelle_count(ptr)
        }
        return 0
    }
    
    func GetAmbKostenstelleStringValue (kostenstelleIndex: UInt32, statValue: LKFAmbStatValue) -> String? {
        if let ptr = context.ptr {
            let valueBuffer = UnsafeMutablePointer<CChar>.allocate(capacity:128)
            //let unsafePath = (path as NSString).utf8String
            LibLKF.lkf_get_amb_kostenstelle_stringvalue(ptr, kostenstelleIndex, statValue.rawValue, valueBuffer, 128)
            let valueString = String(cString: valueBuffer)
            valueBuffer.deallocate()
            return valueString
        }
        return nil
    }

    func GetAmbKostenstelleValue (kostenstelleIndex: UInt32,  statValue: LKFAmbStatValue) -> Int32 {
        if let ptr = context.ptr {
            return LibLKF.lkf_get_amb_kostenstelle_value(ptr, kostenstelleIndex, statValue.rawValue)
        }
        return 0
    }

    func GetAmbKostenstelleValue (kostenstelle: String, statValue: LKFAmbStatValue ) -> UInt32 {
        if let ptr = context.ptr {
            let kostenstelle_char = (kostenstelle as NSString).utf8String
            let res = LibLKF.lkf_get_amb_kostenstelle_counter(ptr, kostenstelle_char, statValue.rawValue);
            if (res >= 0) {
                return UInt32(res)
            }
        }
        return 0
    }
    
    func GetAmbKostenstelleIndex (kostenstelle: String) -> UInt32?
    {
        if let ptr = context.ptr {
            let kostenstelle_char = (kostenstelle as NSString).utf8String
            let res = LibLKF.lkf_get_amb_kostenstelle_index(ptr, kostenstelle_char)
            if (res >= 0) {
                return UInt32(res)
            }
        }
        return nil
    }
}
