//
//  LKFFilterDIAG.swift
//  lkfc
//
//  Created by Alexander Holzer on 07.01.22.
//  Copyright © 2022 Alexander Holzer. All rights reserved.
//

import Foundation

public class LKFFilterDIAG : LKFFilter {
    let diag: String
    let diagKey: Int64
    
    public init (context: LKFContext, diag: String, exactMatch: Bool = true) {
        self.diag = diag.trimmingCharacters(in: .whitespaces)
        self.diagKey = context.diagKey (for: diag)
    }
    
    public override func isIncluded(contact: LKFAufenthalt) -> Bool {
        return contact.findFirstDiag(with: diagKey) != nil
    }
}

public class LKFFilterDiagString : LKFFilter {
    let diag: String
    let diagChar: [CChar]
    let diagCharLength: UInt32
    
    public init? (context: LKFContext, diag: String) {
        let diag = diag.trimmingCharacters(in: .whitespaces)
        guard let diagChar = diag.cString(using: .utf8) else {
            return nil
        }
        self.diag = diag
        self.diagChar = diagChar
        self.diagCharLength = UInt32(diag.count)
    }
    
    public override func isIncluded(contact: LKFAufenthalt) -> Bool {
        return contact.findFirstDiagIndex(diag: diagChar, len: diagCharLength) != nil
    }
}
