package trainings.cdi.starter.impl;

import trainings.cdi.starter.api.ATMTransport;
import trainings.cdi.starter.api.Json;
import trainings.cdi.starter.api.Soap;

import javax.enterprise.inject.Alternative;
import javax.enterprise.inject.Produces;

public class TransportFactory {

    private boolean useJSON = true;
    private boolean behindFirewall = true;

    @Produces
    @Alternative
    public ATMTransport createTransport(@Soap ATMTransport soapTransport, @Json ATMTransport jsonTransport) {
        // look up parameters in some configuration file/LDAP/DB, etc

        System.out.println("ATM transport created with producer based on config");

        if (!behindFirewall) {
            System.out.println("Created Standard transport");
            return new StandardAtmTransport();
        } else {
            if (useJSON) {
                System.out.println("Create JSON transport");
                return jsonTransport;
            } else {
                System.out.println("Created SAOP transport");
                return soapTransport;
            }
        }
    }
}
