using System;

namespace EMPlannerVerificationHost;

internal static class Program
{
    private static int Main(string[] args)
    {
        if (args.Length != 1 || (args[0] != "foundation" && args[0] != "segmentation" && args[0] != "frenet" &&
            args[0] != "corridor" && args[0] != "optimization" && args[0] != "osqp" && args[0] != "osqp-loader" && args[0] != "osqp-probe" &&
            args[0] != "all-foundation" && args[0] != "lateral-model" && args[0] != "lateral-integration" &&
            args[0] != "lateral-real-osqp" && args[0] != "lateral-real-osqp-probe" && args[0] != "lateral-all" &&
            args[0] != "longitudinal-model" && args[0] != "longitudinal-integration" &&
            args[0] != "longitudinal-real-osqp-probe" && args[0] != "trajectory" &&
            args[0] != "em-planning-service" && args[0] != "em-core-all" && args[0] != "coordinator" &&
            args[0] != "executor" && args[0] != "plugin-package" && args[0] != "trajectory-observation" && args[0] != "em-all"))
        {
            Console.Error.WriteLine("Usage: EMPlannerVerificationHost foundation|segmentation|frenet|corridor|optimization|osqp|osqp-loader|all-foundation|lateral-model|lateral-integration|lateral-real-osqp|lateral-all|longitudinal-model|longitudinal-integration|em-core-all|coordinator|executor|plugin-package|trajectory-observation|em-all");
            return 2;
        }

        try
        {
            if (args[0] == "foundation" || args[0] == "all-foundation" || args[0] == "em-all")
            {
                MultiWheelC.TrajectoryPlanning.EMPlanner.FoundationChecks.Run();
                Console.WriteLine("PASS foundation");
            }
            if (args[0] == "segmentation" || args[0] == "all-foundation" || args[0] == "em-all")
            {
                MultiWheelC.TrajectoryPlanning.EMPlanner.SegmentationChecks.Run();
                Console.WriteLine("PASS segmentation");
            }
            if (args[0] == "frenet" || args[0] == "all-foundation" || args[0] == "em-all")
            {
                MultiWheelC.TrajectoryPlanning.EMPlanner.FrenetChecks.Run();
                Console.WriteLine("PASS frenet");
            }
            if (args[0] == "corridor" || args[0] == "all-foundation" || args[0] == "em-all")
            {
                MultiWheelC.TrajectoryPlanning.EMPlanner.CorridorChecks.Run();
                Console.WriteLine("PASS corridor");
            }
            if (args[0] == "optimization" || args[0] == "em-all")
            {
                MultiWheelC.TrajectoryPlanning.EMPlanner.OptimizationChecks.Run();
                Console.WriteLine("PASS optimization");
            }
            if (args[0] == "osqp" || args[0] == "osqp-loader" || args[0] == "em-all")
            {
                MultiWheelC.TrajectoryPlanning.EMPlanner.OsqpChecks.Run();
                Console.WriteLine("PASS osqp-loader");
            }
            if (args[0] == "osqp-probe")
            {
                MultiWheelC.TrajectoryPlanning.EMPlanner.OsqpChecks.RunProbe();
            }
            if (args[0] == "lateral-model" || args[0] == "lateral-all" || args[0] == "em-all")
            {
                MultiWheelC.TrajectoryPlanning.EMPlanner.LateralModelChecks.Run();
                Console.WriteLine("PASS lateral-model");
            }
            if (args[0] == "lateral-integration" || args[0] == "lateral-all" || args[0] == "em-all")
            {
                MultiWheelC.TrajectoryPlanning.EMPlanner.LateralIntegrationChecks.Run();
                Console.WriteLine("PASS lateral-integration");
            }
            if (args[0] == "lateral-real-osqp-probe")
            {
                MultiWheelC.TrajectoryPlanning.EMPlanner.LateralIntegrationChecks.RunRealOsqp();
                Console.WriteLine("PASS lateral-real-osqp");
            }
            if (args[0] == "lateral-real-osqp" || args[0] == "lateral-all" || args[0] == "em-all")
            {
                MultiWheelC.TrajectoryPlanning.EMPlanner.LateralIntegrationChecks.RunRealOsqpInCleanPluginBundle();
                Console.WriteLine("PASS lateral-real-osqp");
            }
            if (args[0] == "longitudinal-model")
            {
                MultiWheelC.TrajectoryPlanning.EMPlanner.LongitudinalModelChecks.Run();
                Console.WriteLine("PASS longitudinal-model");
            }
            if (args[0] == "longitudinal-integration")
            {
                MultiWheelC.TrajectoryPlanning.EMPlanner.LongitudinalIntegrationChecks.Run();
                Console.WriteLine("PASS longitudinal-integration");
            }
            if (args[0] == "longitudinal-real-osqp-probe")
            {
                MultiWheelC.TrajectoryPlanning.EMPlanner.LongitudinalIntegrationChecks.RunRealOsqp();
                Console.WriteLine("PASS longitudinal-real-osqp");
            }
            if (args[0] == "trajectory")
            {
                MultiWheelC.TrajectoryPlanning.EMPlanner.TrajectoryChecks.Run();
                Console.WriteLine("PASS trajectory");
            }
            if (args[0] == "em-planning-service" || args[0] == "em-core-all" || args[0] == "em-all")
            {
                if (args[0] == "em-core-all" || args[0] == "em-all")
                {
                    MultiWheelC.TrajectoryPlanning.EMPlanner.LongitudinalModelChecks.Run();
                    Console.WriteLine("PASS longitudinal-model");
                    MultiWheelC.TrajectoryPlanning.EMPlanner.LongitudinalIntegrationChecks.Run();
                    Console.WriteLine("PASS longitudinal-integration");
                    MultiWheelC.TrajectoryPlanning.EMPlanner.TrajectoryChecks.Run();
                    Console.WriteLine("PASS trajectory");
                }
                MultiWheelC.TrajectoryPlanning.EMPlanner.EmPlanningServiceChecks.Run();
                Console.WriteLine("PASS em-planning-service");
            }
            if (args[0] == "coordinator" || args[0] == "em-all")
            {
                CoordinatorChecks.Run();
                Console.WriteLine("PASS coordinator");
            }
            if (args[0] == "executor" || args[0] == "em-all")
            {
                ExecutorChecks.Run();
                Console.WriteLine("PASS executor");
            }
            if (args[0] == "plugin-package" || args[0] == "em-all")
            {
                PluginPackagingChecks.Run();
                Console.WriteLine("PASS plugin-package");
            }
            if (args[0] == "trajectory-observation" || args[0] == "em-all")
            {
                TrajectoryObservationChecks.Run();
                Console.WriteLine("PASS trajectory-observation");
            }
            if (args[0] == "em-all")
            {
                CoordinatorChecks.RunRollingEndToEnd();
                Console.WriteLine("PASS rolling-end-to-end");
                ExecutorChecks.RunRollingEndToEnd();
                Console.WriteLine("PASS rolling-execution-tail");
            }
            return 0;
        }
        catch (Exception exception)
        {
            Console.Error.WriteLine(exception);
            return 1;
        }
    }
}
