//
//  File.swift
//  LKF
//
//  Created by Alexander Holzer on 06.01.22.
//  Copyright © 2022 Alexander Holzer. All rights reserved.
//

import Foundation

public class LKFFilterMEL : LKFFilter {
    let mel: String
    let melKey : Int64
    
    public init (context: LKFContext, mel: String) {
        self.mel = mel.trimmingCharacters(in: .whitespaces)
        self.melKey  = context.melKey (for: mel)
    }
    
    public override func isIncluded(contact: LKFAufenthalt) -> Bool {
        return contact.findFirstMel (with: melKey) != nil
    }
}

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