package org.fakekoji.jobmanager;

import org.fakekoji.core.AccessibleSettings;
import org.fakekoji.jobmanager.model.BuildJob;
import org.fakekoji.jobmanager.model.PlatformBumpVariant;
import org.fakekoji.jobmanager.model.TestJob;
import org.fakekoji.model.Platform;

public class PlatformBumper extends JobModifier {

    private final Platform from;
    private final Platform to;
    private final PlatformBumpVariant variant;

    public PlatformBumper(
            final AccessibleSettings settings,
            final Platform from,
            final Platform to,
            final PlatformBumpVariant variant
    ) {
        super(settings);
        this.from = from;
        this.to = to;
        this.variant = variant;
    }

    @Override
    boolean shouldPass(BuildJob job) {
        return isFromPlatform(job.getPlatform());
    }

    @Override
    boolean shouldPass(TestJob job) {
        return isFromPlatform(job.getPlatform()) || isFromBuildPlatform(job.getBuildPlatform());
    }

    @Override
    BuildJob transform(BuildJob job) {
        return new BuildJob(
                job.getPlatformProvider(),
                job.getProjectName(),
                job.getProduct(),
                job.getJdkVersion(),
                job.getBuildProviders(),
                job.getTask(),
                to,
                job.getVariants(),
                job.getScriptsRoot(),
                job.getProjectVariables()
        );
    }

    @Override
    TestJob transform(TestJob job) {
        final Platform platform = isFromPlatform(job.getPlatform()) ? to : job.getPlatform();
        final Platform buildPlatform = isFromBuildPlatform(job.getBuildPlatform()) ? to : job.getBuildPlatform();
        return new TestJob(
                job.getPlatformProvider(),
                job.getProjectName(),
                job.getProjectType(),
                job.getProduct(),
                job.getJdkVersion(),
                job.getBuildProviders(),
                job.getTask(),
                platform,
                job.getVariants(),
                buildPlatform,
                job.getBuildPlatformProvider(),
                job.getBuildTask(),
                job.getBuildVariants(),
                job.getProjectSubpackageBlacklist(),
                job.getProjectSubpackageWhitelist(),
                job.getScriptsRoot(),
                job.getProjectVariables()
        );
    }

    private boolean isFromPlatform(final Platform platform) {
        return platform.getId().equals(from.getId());
    }

    private boolean isFromBuildPlatform(final Platform platform) {
        return platform != null && isFromPlatform(platform);
    }
}

@@ -792,49 +792,225 @@
     
-return isFromPlatform(job.getPlatform());
+switch (variant) %7B%0A            case BOTH:%0A            case BUILD_ONLY:%0A                return isFromPlatform(job.getPlatform());%0A            case TEST_ONLY:%0A            default:%0A                return false;%0A        %7D
 %0A   
@@ -1057,32 +1057,90 @@
 (TestJob job) %7B%0A
+        switch (variant) %7B%0A            case BOTH:%0A        
         return i
@@ -1216,24 +1216,268 @@
 latform());%0A
+            case BUILD_ONLY:%0A                return isFromBuildPlatform(job.getBuildPlatform());%0A            case TEST_ONLY:%0A                return isFromPlatform(job.getPlatform());%0A            default:%0A                return false;%0A        %7D%0A
     %7D%0A%0A    @
@@ -2016,184 +2016,772 @@
 form
- = isFromPlatform(job.getPlatform()) ? to : job.getPlatform();%0A        final Platform buildPlatform = isFromBuildPlatform(job.getBuildPlatform()) ? to : job.getBuildPlatform();
+;%0A        final Platform buildPlatform;%0A        switch (variant) %7B%0A            case BOTH:%0A                platform = isFromPlatform(job.getPlatform()) ? to : job.getPlatform();%0A                buildPlatform = isFromBuildPlatform(job.getBuildPlatform()) ? to : job.getBuildPlatform();%0A                break;%0A            case BUILD_ONLY:%0A                platform = job.getPlatform();%0A                buildPlatform = isFromBuildPlatform(job.getBuildPlatform()) ? to : job.getBuildPlatform();%0A                break;%0A            case TEST_ONLY:%0A                platform = isFromPlatform(job.getPlatform()) ? to : job.getPlatform();%0A                buildPlatform = job.getBuildPlatform();%0A                break;%0A            default:%0A                return job;%0A        %7D
 %0A   

Use PlatformBumpVariant switch in PlatformBumper