// Path: src/main/java/ch/urbanfox/freqtrade/FreqTradeProperties.java
// @Configuration
// @ConfigurationProperties(prefix = "freqtrade")
// public class FreqTradeProperties {
// 
//     private State initialState;
// 
//     private int maxOpenTrades;
// 
//     private Currency stakeCurrency;
// 
//     private BigDecimal stakeAmount;
// 
//     private boolean dryRun = false;
// 
//     private Map<Long, BigDecimal> minimalRoi = new TreeMap<>();
// 
//     private BigDecimal stopLoss;
// 
//     private List<CurrencyPair> pairWhitelist = new ArrayList<>();
// 
//     private BittrexProperties bittrex;
// 
//     private TelegramProperties telegram;
// 
//     public State getInitialState() {
//         return initialState;
//     }
// 
//     public void setInitialState(State initialState) {
//         this.initialState = initialState;
//     }
// 
//     public int getMaxOpenTrades() {
//         return maxOpenTrades;
//     }
// 
//     public void setMaxOpenTrades(int maxOpenTrades) {
//         this.maxOpenTrades = maxOpenTrades;
//     }
// 
//     public Currency getStakeCurrency() {
//         return stakeCurrency;
//     }
// 
//     public void setStakeCurrency(Currency stakeCurrency) {
//         this.stakeCurrency = stakeCurrency;
//     }
// 
//     public BigDecimal getStakeAmount() {
//         return stakeAmount;
//     }
// 
//     public void setStakeAmount(BigDecimal stakeAmount) {
//         this.stakeAmount = stakeAmount;
//     }
// 
//     public boolean isDryRun() {
//         return dryRun;
//     }
// 
//     public void setDryRun(boolean dryRun) {
//         this.dryRun = dryRun;
//     }
// 
//     public Map<Long, BigDecimal> getMinimalRoi() {
//         return minimalRoi;
//     }
// 
//     public void setMinimalRoi(Map<Long, BigDecimal> minimalRoi) {
//         this.minimalRoi = minimalRoi;
//     }
// 
//     public BigDecimal getStopLoss() {
//         return stopLoss;
//     }
// 
//     public void setStopLoss(BigDecimal stopLoss) {
//         this.stopLoss = stopLoss;
//     }
// 
//     public List<CurrencyPair> getPairWhitelist() {
//         return pairWhitelist;
//     }
// 
//     public void setPairWhitelist(List<CurrencyPair> pairWhitelist) {
//         this.pairWhitelist = pairWhitelist;
//     }
// 
//     public BittrexProperties getBittrex() {
//         return bittrex;
//     }
// 
//     public void setBittrex(BittrexProperties bittrex) {
//         this.bittrex = bittrex;
//     }
// 
//     public TelegramProperties getTelegram() {
//         return telegram;
//     }
// 
//     public void setTelegram(TelegramProperties telegram) {
//         this.telegram = telegram;
//     }
// 
// }
// 
// Path: src/main/java/ch/urbanfox/freqtrade/event/model/CommandEvent.java
// public class CommandEvent {
// 
//     private final String command;
// 
//     private final String[] params;
// 
//     public CommandEvent(String command, String... params) {
//         this.command = command;
//         this.params = params;
//     }
// 
//     public String getCommand() {
//         return command;
//     }
// 
//     public String[] getParams() {
//         return params;
//     }
// 
//     @Override
//     public String toString() {
//         return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
//     }
// }


import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.telegram.telegrambots.api.objects.Message;
import org.telegram.telegrambots.api.objects.Update;
import org.telegram.telegrambots.bots.TelegramLongPollingBot;
import ch.urbanfox.freqtrade.FreqTradeProperties;
import ch.urbanfox.freqtrade.event.model.CommandEvent;
package ch.urbanfox.freqtrade.telegram;




public class FreqTradeTelegramBot extends TelegramLongPollingBot {

    private static final Logger LOGGER = LoggerFactory.getLogger(FreqTradeTelegramBot.class);

    private final ApplicationContext context;

    private final TelegramProperties telegramProperties;

    public FreqTradeTelegramBot(ApplicationContext context) {
        this.context = context;
        FreqTradeProperties properties = context.getBean(FreqTradeProperties.class);
        this.telegramProperties = properties.getTelegram();
    }

    @Override
    public void onUpdateReceived(Update update) {
        LOGGER.debug("Received: {}", update);
        final Message message = Optional.ofNullable(update.getMessage()).orElse(update.getEditedMessage());
        final Long chatId = message.getChatId();
        if (!telegramProperties.getChatId().equals(chatId)) {
            LOGGER.debug("Unauthorized access, ignoring (chat_id: {}, expected: {})", update.getMessage().getChatId(), telegramProperties.getChatId());
            return;
        }

        final String command = message.getText();
// Path: src/main/java/ch/urbanfox/freqtrade/FreqTradeProperties.java
// @Configuration
// @ConfigurationProperties(prefix = "freqtrade")
// public class FreqTradeProperties {
// 
//     private State initialState;
// 
//     private int maxOpenTrades;
// 
//     private Currency stakeCurrency;
// 
//     private BigDecimal stakeAmount;
// 
//     private boolean dryRun = false;
// 
//     private Map<Long, BigDecimal> minimalRoi = new TreeMap<>();
// 
//     private BigDecimal stopLoss;
// 
//     private List<CurrencyPair> pairWhitelist = new ArrayList<>();
// 
//     private BittrexProperties bittrex;
// 
//     private TelegramProperties telegram;
// 
//     public State getInitialState() {
//         return initialState;
//     }
// 
//     public void setInitialState(State initialState) {
//         this.initialState = initialState;
//     }
// 
//     public int getMaxOpenTrades() {
//         return maxOpenTrades;
//     }
// 
//     public void setMaxOpenTrades(int maxOpenTrades) {
//         this.maxOpenTrades = maxOpenTrades;
//     }
// 
//     public Currency getStakeCurrency() {
//         return stakeCurrency;
//     }
// 
//     public void setStakeCurrency(Currency stakeCurrency) {
//         this.stakeCurrency = stakeCurrency;
//     }
// 
//     public BigDecimal getStakeAmount() {
//         return stakeAmount;
//     }
// 
//     public void setStakeAmount(BigDecimal stakeAmount) {
//         this.stakeAmount = stakeAmount;
//     }
// 
//     public boolean isDryRun() {
//         return dryRun;
//     }
// 
//     public void setDryRun(boolean dryRun) {
//         this.dryRun = dryRun;
//     }
// 
//     public Map<Long, BigDecimal> getMinimalRoi() {
//         return minimalRoi;
//     }
// 
//     public void setMinimalRoi(Map<Long, BigDecimal> minimalRoi) {
//         this.minimalRoi = minimalRoi;
//     }
// 
//     public BigDecimal getStopLoss() {
//         return stopLoss;
//     }
// 
//     public void setStopLoss(BigDecimal stopLoss) {
//         this.stopLoss = stopLoss;
//     }
// 
//     public List<CurrencyPair> getPairWhitelist() {
//         return pairWhitelist;
//     }
// 
//     public void setPairWhitelist(List<CurrencyPair> pairWhitelist) {
//         this.pairWhitelist = pairWhitelist;
//     }
// 
//     public BittrexProperties getBittrex() {
//         return bittrex;
//     }
// 
//     public void setBittrex(BittrexProperties bittrex) {
//         this.bittrex = bittrex;
//     }
// 
//     public TelegramProperties getTelegram() {
//         return telegram;
//     }
// 
//     public void setTelegram(TelegramProperties telegram) {
//         this.telegram = telegram;
//     }
// 
// }
// 
// Path: src/main/java/ch/urbanfox/freqtrade/event/model/CommandEvent.java
// public class CommandEvent {
// 
//     private final String command;
// 
//     private final String[] params;
// 
//     public CommandEvent(String command, String... params) {
//         this.command = command;
//         this.params = params;
//     }
// 
//     public String getCommand() {
//         return command;
//     }
// 
//     public String[] getParams() {
//         return params;
//     }
// 
//     @Override
//     public String toString() {
//         return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
//     }
// }


// Path: src/main/java/ch/urbanfox/freqtrade/telegram/FreqTradeTelegramBot.java
import java.util.Optional;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;
import org.telegram.telegrambots.api.objects.Message;
import org.telegram.telegrambots.api.objects.Update;
import org.telegram.telegrambots.bots.TelegramLongPollingBot;
import ch.urbanfox.freqtrade.FreqTradeProperties;
import ch.urbanfox.freqtrade.event.model.CommandEvent;

package ch.urbanfox.freqtrade.telegram;




public class FreqTradeTelegramBot extends TelegramLongPollingBot {

    private static final Logger LOGGER = LoggerFactory.getLogger(FreqTradeTelegramBot.class);

    private final ApplicationContext context;

    private final TelegramProperties telegramProperties;

    public FreqTradeTelegramBot(ApplicationContext context) {
        this.context = context;
        FreqTradeProperties properties = context.getBean(FreqTradeProperties.class);
        this.telegramProperties = properties.getTelegram();
    }

    @Override
    public void onUpdateReceived(Update update) {
        LOGGER.debug("Received: {}", update);
        final Message message = Optional.ofNullable(update.getMessage()).orElse(update.getEditedMessage());
        final Long chatId = message.getChatId();
        if (!telegramProperties.getChatId().equals(chatId)) {
            LOGGER.debug("Unauthorized access, ignoring (chat_id: {}, expected: {})", update.getMessage().getChatId(), telegramProperties.getChatId());
            return;
        }

        final String command = message.getText();
        context.publishEvent(new CommandEvent(command));