//
//  LKFIntAbtResult.swift
//  lkfc
//
//  Created by Alexander Holzer on 20.10.18.
//  Copyright © 2018 Alexander Holzer. All rights reserved.
//

import Foundation
@_implementationOnly import LibLKF

public class LKFIntAbtResult {
    
    public let sapsResults : [LKFIntAbtSAPSResult]
    
    public var score : Int32 {
        if sapsResults.count >= 1 {
            return sapsResults[0].score
        }
        return 0
    }
    
    public var scoreParts : [Int32] {
        if sapsResults.count >= 1 {
            return sapsResults[0].scoreParts
        }
        return []
    }
    
    public var gcs: Int32 {
        if sapsResults.count >= 1 {
            return sapsResults[0].gcs
        }
        return 0
    }
    
    public var partString : String {
        if sapsResults.count >= 1 {
            return sapsResults[0].partString
        }
        return ""
    }
    
    init(context: LKFContext, index: UInt32) {
        
        let sapsCount = LibLKF.lkf_int_getIntAufenthaltSAPSCount(context.ptr!, index)
        
        if sapsCount == 0 {
            sapsResults = []
        }
        else {
            var arr = [LKFIntAbtSAPSResult]()
        
            for i in 0..<sapsCount {
                arr.append(LKFIntAbtSAPSResult(context: context, index: index, sapsIndex: i))
            }
            sapsResults = arr
        }
    }
    
    init? (aufenthalt: LKFAufenthalt, index: UInt32) {
        
        if LibLKF.lkf_int_getAufIsIntAbt(aufenthalt.ptr, index) == 0 {
            return nil
        }
        
        let sapsCount = LibLKF.lkf_int_getAufIntAbtSAPSCount (aufenthalt.ptr, index)
        
        if sapsCount == 0 {
            sapsResults = []
        }
        else {
            var arr = [LKFIntAbtSAPSResult]()
            for i in 0..<sapsCount {
                arr.append(LKFIntAbtSAPSResult(aufenthalt: aufenthalt, index: index, sapsIndex: i))
            }
            sapsResults = arr
        }
    }
}
