//
//  LKFAnonymizationSettings.swift
//  lkfc
//
//  Created by Alexander Holzer on 16.06.23.
//  Copyright © 2023 Alexander Holzer. All rights reserved.
//

import Foundation

open class LKFAnonymizationSettings {
    public let kanr : String?
    public let keepStamm : Bool
    public let nextkey : Int?
    public let addYears: Int?
    public let dates: Int?
    public let ambToStat: Int?
    public let statToAmb: Int?
    
    public let copyFlag : Int32
    
    public init (kanr: String? = nil, addYears: Int? = nil, nextKey: Int? = nil, keepStamm: Bool = true, dates: Int? = nil, copyFlag : Int32? = nil, statToAmb: Int? = nil, ambToStat: Int? = nil) {
        self.kanr = kanr
        self.keepStamm = keepStamm
        self.addYears = addYears
        self.nextkey = nextKey
        self.dates = dates
        if let copyFlag {
            self.copyFlag = copyFlag
        }
        else if kanr != nil {
            self.copyFlag = 15
        }
        else {
            self.copyFlag = 255
        }
        self.statToAmb = statToAmb
        self.ambToStat = ambToStat
    }
    
    public func createCommandLine() -> String {
        var arr = [String]()
        if let kanr, kanr.count > 0 {
            arr.append("kanr=\(kanr)")
        }
        if let addYears {
            arr.append("addyears=\(addYears)")
        }
        if let nextkey {
            if nextkey == 0 {
                arr.append("keepkey");
            }
            else {
                arr.append("nextkey=\(nextkey)")
            }
        }
        if keepStamm {
            arr.append("stamm=off");
        }
        if let dates {
            arr.append("dates=\(dates)")
        }
        
        if let ambToStat {
            arr.append("ambToStat=\(ambToStat)");
        }
        
        if let statToAmb {
            arr.append("statToAmb=\(statToAmb)");
        }
        
        return arr.joined(separator: "|");
    }
}
