generateCopyWithMethods static method

String generateCopyWithMethods({
  1. required List<NameType> classFields,
  2. required List<NameType> interfaceFields,
  3. required String interfaceName,
  4. required String className,
  5. required bool isClassAbstract,
  6. required List<NameType> interfaceGenerics,
  7. bool generateCopyWithFn = false,
  8. List<String> knownClasses = const [],
  9. List<NameType> classGenerics = const [],
  10. bool nonSealed = false,
  11. bool hidePublicConstructor = false,
})

Generate copyWith methods (now generates simple copyWith without patchInput) AND separate patchWith methods

Implementation

static String generateCopyWithMethods({
  required List<NameType> classFields,
  required List<NameType> interfaceFields,
  required String interfaceName,
  required String className,
  required bool isClassAbstract,
  required List<NameType> interfaceGenerics,
  bool generateCopyWithFn = false,
  List<String> knownClasses = const [],
  List<NameType> classGenerics = const [],
  bool nonSealed = false,
  bool hidePublicConstructor = false,
}) {
  final methods = <String>[];

  // Generate simple copyWith methods (without patchInput)
  final copyWithMethods = MethodGeneratorFacade.generateCopyWithMethods(
    classFields: classFields,
    interfaceFields: interfaceFields,
    interfaceName: interfaceName,
    className: className,
    isClassAbstract: isClassAbstract,
    interfaceGenerics: interfaceGenerics,
    generateCopyWithFn: generateCopyWithFn,
    knownClasses: knownClasses,
    classGenerics: classGenerics,
    nonSealed: nonSealed,
    hidePublicConstructor: hidePublicConstructor,
  );

  if (copyWithMethods.isNotEmpty) {
    methods.add(copyWithMethods);
  }

  // Generate separate patchWith methods (with patchInput)
  final patchWithMethods = MethodGeneratorFacade.generatePatchWithMethods(
    classFields: classFields,
    interfaceFields: interfaceFields,
    interfaceName: interfaceName,
    className: className,
    isClassAbstract: isClassAbstract,
    interfaceGenerics: interfaceGenerics,
    generatePatchWithFn: generateCopyWithFn, // Use same flag for consistency
    knownClasses: knownClasses,
    classGenerics: classGenerics,
    nonSealed: nonSealed,
    hidePublicConstructor: hidePublicConstructor,
  );

  if (patchWithMethods.isNotEmpty) {
    methods.add(patchWithMethods);
  }

  return methods.join('\n\n');
}