//
//  ColorsToolOptions.swift
//
//
//  Created by Thibaut Schmitt on 17/01/2022.
//

// CPD-OFF

import ArgumentParser
import Foundation
import ToolCore

// swiftlint:disable no_grouping_extension

struct ColorsToolOptions: ParsableArguments {

    @Flag(
        name: [.customShort("f"), .customShort("F")],
        help: "Should force generation"
    )
    var forceGeneration = false

    @Argument(
        help: "Input files where colors ared defined.",
        transform: { $0.replaceTiltWithHomeDirectoryPath() }
    )
    var inputFile: String

    @Option(help: "Color style to generate: light for light colors only, or all for dark and light colors")
    var style: ColorStyle

    @Option(
        help: "Path of xcassets where to generate colors",
        transform: { $0.replaceTiltWithHomeDirectoryPath() }
    )
    var xcassetsPath: String

    @Option(help: "Tell if it will generate static properties or not")
    var staticMembers: Bool = false

    @Option(
        name: .customLong("visibility"),
        help: "Visibility of extension and properties. Possibles values: public, private, package, internal. Default is internal",
        completion: .list(["public", "private", "package", "internal"])
    )
    var extensionVisibility: ExtensionVisibility = .internal

    @Option(
        help: "Bundle where the asset are generated"
    )
    var assetBundle: AssetBundle = .main

    @Option(
        help: "Path where to generate the extension.",
        transform: { $0.replaceTiltWithHomeDirectoryPath() }
    )
    var extensionOutputPath: String?

    @Option(help: "SwiftUI extension name. If not specified, no extension will be generated.")
    var extensionName: String?

    @Option(help: "UIKit extension name. If not specified, no extension will be generated.")
    var extensionNameUIKit: String?

    @Option(help: "Extension suffix. Ex: MyApp, it will generate {extensionName}+ColorsMyApp.swift")
    var extensionSuffix: String?
}

// MARK: - Computed var

extension ColorsToolOptions {

    // MARK: - SwiftUI

    var extensionFileName: String? {
        guard let extensionName else { return nil }

        if let extensionSuffix {
            return "\(extensionName)+\(extensionSuffix).swift"
        }
        return "\(extensionName).swift"
    }

    var extensionFilePath: String? {
        guard let extensionOutputPath, let extensionFileName else { return nil }

        return "\(extensionOutputPath)/\(extensionFileName)"
    }

    // MARK: - UIKit

    var extensionFileNameUIKit: String? {
        guard let extensionNameUIKit else { return nil }

        if let extensionSuffix {
            return "\(extensionNameUIKit)+\(extensionSuffix).swift"
        }
        return "\(extensionNameUIKit).swift"
    }

    var extensionFilePathUIKit: String? {
        guard let extensionOutputPath, let extensionFileNameUIKit else { return nil }

        return "\(extensionOutputPath)/\(extensionFileNameUIKit)"
    }
}// CPD-ON
