//
//  StringsConfiguration+Runnable.swift
//  
//
//  Created by Thibaut Schmitt on 30/08/2022.
//

import Foundation

extension StringsConfiguration: Runnable {

    func run(projectDirectory: String, force: Bool) {
        let args = getArguments(projectDirectory: projectDirectory, force: force)
        Stringium.main(args)
    }

    func getArguments(projectDirectory: String, force: Bool) -> [String] {
        var args = [String]()

        if force {
            args += ["-f"]
        }

        args += [
            inputFile.prependIfRelativePath(projectDirectory),
            "--output-path",
            outputPath.prependIfRelativePath(projectDirectory),
            "--langs",
            langs,
            "--default-lang",
            defaultLang
        ]

        // Add optional parameters
        [
            ("--extension-output-path", extensionOutputPath?.prependIfRelativePath(projectDirectory)),
            ("--extension-name", extensionName),
            ("--extension-suffix", extensionSuffix),
            ("--visibility", visibility),
            ("--asset-bundle", assetBundle),
            ("--xc-strings", xcStrings?.description),
            ("--static-members", staticMembers?.description)
        ].forEach { argumentName, argumentValue in
            if let argumentValue {
                args += [
                    argumentName,
                    argumentValue
                ]
            }
        }

        return args
    }
}
