//
//  StringsFileGenerator+XCStringsExpectation.swift
//  ResgenSwift
//
//  Created by Thibaut Schmitt on 30/04/2025.
//

@testable import ResgenSwift

extension XCStringDefinition {

    enum Mock {

        static func getDefinitionSectionOne(
            defOneFr: String = "Section Un - Definition Un",
            defOneEn: String = "Section One - Definition One",
            defOneComment: String? = nil,
            defTwoFr: String = "Section Un - Definition Deux",
            defTwoEn: String = "Section One - Definition Two",
            defTwoComment: String? = nil
        ) -> [XCStringDefinition] {
            [
                XCStringDefinition(
                    title: "s1_def_one",
                    content: XCStringDefinitionContent(
                        comment: defOneComment,
                        extractionState: "manual",
                        localizations: XCStringLocalizationContainer(
                            localizations: getXCStringLocalization(
                                defFr: defOneFr,
                                defEn: defOneEn
                            )
                        )
                    )
                ),
                XCStringDefinition(
                    title: "s1_def_two",
                    content: XCStringDefinitionContent(
                        comment: defTwoComment,
                        extractionState: "manual",
                        localizations: XCStringLocalizationContainer(
                            localizations: getXCStringLocalization(
                                defFr: defTwoFr,
                                defEn: defTwoEn
                            )
                        )
                    )
                )
            ]
        }

        static func getDefinitionSectionTwo(
            defOneFr: String = "Section Deux - Definition Un",
            defOneEn: String = "Section Two - Definition One",
            defOneComment: String? = nil,
            defTwoFr: String = "Section Deux - Definition Deux",
            defTwoEn: String? = nil,
            defTwoComment: String? = nil
        ) -> [XCStringDefinition] {
            [
                XCStringDefinition(
                    title: "s2_def_one",
                    content: XCStringDefinitionContent(
                        comment: defOneComment,
                        extractionState: "manual",
                        localizations: XCStringLocalizationContainer(
                            localizations: getXCStringLocalization(
                                defFr: defOneFr,
                                defEn: defOneEn
                            )
                        )
                    )
                ),
                XCStringDefinition(
                    title: "s2_def_two",
                    content: XCStringDefinitionContent(
                        comment: defTwoComment,
                        extractionState: "manual",
                        localizations: XCStringLocalizationContainer(
                            localizations: getXCStringLocalization(
                                defFr: defTwoFr,
                                defEn: defTwoEn ?? ""
                            )
                        )
                    )
                )
            ]
        }

        // MARK: - Private methods

        private static func getXCStringLocalization(
            defFr: String,
            defEn: String
        ) -> [XCStringLocalization] {
            var localizations = [XCStringLocalization]()

            if defFr.isEmpty == false {
                localizations.append(
                    XCStringLocalization(
                        lang: "fr",
                        content: XCStringLocalizationLangContent(
                            stringUnit: DefaultStringUnit(
                                state: "translated",
                                value: defFr
                            )
                        )
                    )
                )
            }

            if defEn.isEmpty == false {
                localizations.append(
                    XCStringLocalization(
                        lang: "en",
                        content: XCStringLocalizationLangContent(
                            stringUnit: DefaultStringUnit(
                                state: "translated",
                                value: defEn
                            )
                        )
                    )
                )
            }

            return localizations
        }
    }
}
