import java.util.HashMap;
import java.util.Map;

public class Loop {

    public static Map<String, Integer> parseCommandLineArgs(String[] args) {
        Map<String, Integer> parameters = new HashMap<>();
        try {
            for (int i = 0; i < args.length; i++) {
                if (args[i].startsWith("-")) {
                    String parameterName = args[i].substring(1);
                    if (i + 1 < args.length) {
                        try {
                            int parameterValue = Integer.parseInt(args[i + 1]);
                            parameters.put(parameterName, parameterValue);
                            i++;
                        } catch (NumberFormatException e) {
                            System.err.println("Error: Invalid value for parameter " + parameterName + ": " + args[i + 1]);
                            return null;
                        }
                    } else {
                        System.err.println("Error: Missing value for parameter " + parameterName);
                        return null;
                    }
                } else {
                    System.err.println("Warning: Ignoring invalid argument: " + args[i]);
                }
            }
        } catch (Exception e) {
            System.err.println("An unexpected error occurred: " + e.getMessage());
            return null;
        }

        return parameters;
    }

    public static void main(String[] args) {
        Map<String, Integer> atmParams = parseCommandLineArgs(args);

        if (atmParams != null) {
            int t = atmParams.getOrDefault("t", 0);
            int k = atmParams.getOrDefault("k", 0);
            int m = atmParams.getOrDefault("m", 0);
            int n = atmParams.getOrDefault("n", 0);

            ATM atm = new ATM();
            CardReader cr = new CardReader(atm);
            Display display = new Display();
            display.display(Display.get_default_display());
            atm.setMinimumAmount(n);
            atm.setTotalFund(t);
            atm.setMaximum_withdrawar_pday_pacc(k);
            atm.setMaximum_withdrawar_ptrans(m);

            while (true) {

                if ATM.checkAvailabilityOfCashInATM()
                // TODO wait for signal from 

            }

        } else {
            System.err.println("Failed to initialize ATM parameters from command line.");
        }
    }
}
