package net.minecraft.util.datafix.fixes;

import com.mojang.datafixers.util.Pair;
import java.util.function.Function;
import com.mojang.serialization.DynamicOps;
import com.mojang.datafixers.types.templates.TaggedChoice;
import com.mojang.datafixers.TypeRewriteRule;
import com.mojang.datafixers.schemas.Schema;
import com.mojang.datafixers.DSL;
import com.mojang.datafixers.DataFix;

public class AddNewChoices extends DataFix {
    private final String name;
    private final DSL.TypeReference type;
    
    public AddNewChoices(final Schema schema, final String string, final DSL.TypeReference typeReference) {
        super(schema, true);
        this.name = string;
        this.type = typeReference;
    }
    
    public TypeRewriteRule makeRule() {
        final TaggedChoice.TaggedChoiceType<?> taggedChoiceType2 = this.getInputSchema().findChoiceType(this.type);
        final TaggedChoice.TaggedChoiceType<?> taggedChoiceType3 = this.getOutputSchema().findChoiceType(this.type);
        return this.cap(this.name, taggedChoiceType2, taggedChoiceType3);
    }
    
    protected final <K> TypeRewriteRule cap(final String string, final TaggedChoice.TaggedChoiceType<K> taggedChoiceType2, final TaggedChoice.TaggedChoiceType<?> taggedChoiceType3) {
        // 
        // This method could not be decompiled.
        // 
        // Original Bytecode:
        // 
        //     1: invokevirtual   com/mojang/datafixers/types/templates/TaggedChoice$TaggedChoiceType.getKeyType:()Lcom/mojang/datafixers/types/Type;
        //     4: aload_3         /* taggedChoiceType3 */
        //     5: invokevirtual   com/mojang/datafixers/types/templates/TaggedChoice$TaggedChoiceType.getKeyType:()Lcom/mojang/datafixers/types/Type;
        //     8: if_acmpeq       21
        //    11: new             Ljava/lang/IllegalStateException;
        //    14: dup            
        //    15: ldc             "Could not inject: key type is not the same"
        //    17: invokespecial   java/lang/IllegalStateException.<init>:(Ljava/lang/String;)V
        //    20: athrow         
        //    21: aload_3         /* taggedChoiceType3 */
        //    22: astore          taggedChoiceType5
        //    24: aload_0         /* this */
        //    25: aload_1         /* string */
        //    26: aload_2         /* taggedChoiceType2 */
        //    27: aload           taggedChoiceType5
        //    29: aload_0         /* this */
        //    30: aload           taggedChoiceType5
        //    32: invokedynamic   BootstrapMethod #0, apply:(Lnet/minecraft/util/datafix/fixes/AddNewChoices;Lcom/mojang/datafixers/types/templates/TaggedChoice$TaggedChoiceType;)Ljava/util/function/Function;
        //    37: invokevirtual   net/minecraft/util/datafix/fixes/AddNewChoices.fixTypeEverywhere:(Ljava/lang/String;Lcom/mojang/datafixers/types/Type;Lcom/mojang/datafixers/types/Type;Ljava/util/function/Function;)Lcom/mojang/datafixers/TypeRewriteRule;
        //    40: areturn        
        //    Signature:
        //  <K:Ljava/lang/Object;>(Ljava/lang/String;Lcom/mojang/datafixers/types/templates/TaggedChoice$TaggedChoiceType<TK;>;Lcom/mojang/datafixers/types/templates/TaggedChoice$TaggedChoiceType<*>;)Lcom/mojang/datafixers/TypeRewriteRule;
        //    MethodParameters:
        //  Name               Flags  
        //  -----------------  -----
        //  string             
        //  taggedChoiceType2  
        //  taggedChoiceType3  
        //    StackMapTable: 00 01 15
        // 
        // The error that occurred was:
        // 
        // java.lang.IllegalStateException: Could not infer any expression.
        //     at com.strobel.decompiler.ast.TypeAnalysis.runInference(TypeAnalysis.java:374)
        //     at com.strobel.decompiler.ast.TypeAnalysis.run(TypeAnalysis.java:96)
        //     at com.strobel.decompiler.ast.AstOptimizer.optimize(AstOptimizer.java:344)
        //     at com.strobel.decompiler.ast.AstOptimizer.optimize(AstOptimizer.java:42)
        //     at com.strobel.decompiler.languages.java.ast.AstMethodBodyBuilder.createMethodBody(AstMethodBodyBuilder.java:214)
        //     at com.strobel.decompiler.languages.java.ast.AstMethodBodyBuilder.createMethodBody(AstMethodBodyBuilder.java:99)
        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.createMethodBody(AstBuilder.java:782)
        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.createMethod(AstBuilder.java:675)
        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.addTypeMembers(AstBuilder.java:552)
        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.createTypeCore(AstBuilder.java:519)
        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.createTypeNoCache(AstBuilder.java:161)
        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.createType(AstBuilder.java:150)
        //     at com.strobel.decompiler.languages.java.ast.AstBuilder.addType(AstBuilder.java:125)
        //     at cuchaz.enigma.SourceProvider.getSources(SourceProvider.java:85)
        //     at cuchaz.enigma.EnigmaProject$JarExport.decompileClass(EnigmaProject.java:241)
        //     at cuchaz.enigma.EnigmaProject$JarExport.lambda$decompile$1(EnigmaProject.java:230)
        //     at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:195)
        //     at java.base/java.util.ArrayList$ArrayListSpliterator.forEachRemaining(ArrayList.java:1654)
        //     at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:484)
        //     at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:474)
        //     at java.base/java.util.stream.ReduceOps$ReduceTask.doLeaf(ReduceOps.java:952)
        //     at java.base/java.util.stream.ReduceOps$ReduceTask.doLeaf(ReduceOps.java:926)
        //     at java.base/java.util.stream.AbstractTask.compute(AbstractTask.java:327)
        //     at java.base/java.util.concurrent.CountedCompleter.exec(CountedCompleter.java:746)
        //     at java.base/java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:290)
        //     at java.base/java.util.concurrent.ForkJoinPool$WorkQueue.topLevelExec(ForkJoinPool.java:1020)
        //     at java.base/java.util.concurrent.ForkJoinPool.scan(ForkJoinPool.java:1656)
        //     at java.base/java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1594)
        //     at java.base/java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:177)
        // 
        throw new IllegalStateException("An error occurred while decompiling this method.");
    }
}
