package org.jebot.handler.impl.price;

import com.pengrad.telegrambot.request.SendMessage;
import com.pengrad.telegrambot.response.SendResponse;
import lombok.extern.slf4j.Slf4j;
import org.jebot.handler.AbstractHandler;
import org.jebot.handler.dto.BotMessage;
import org.jebot.util.PriceUtil;
import org.jebot.util.QueryType;

import static org.jebot.constant.Constant.*;

@Slf4j
public class PriceQueryHandler extends AbstractHandler {
    public boolean msgHandler(BotMessage botMessage) {
        if (botMessage.messageTextIsEmpty()) {
            return false;
        }

        String text = botMessage.getMessageText();
        switch (text) {
            case QUERY_USDT_TO_ALIPAY_CNY:
                text = PriceUtil.QueryUsdtToCny(QueryType.ALIPAY);
                break;
            case QUERY_USDT_TO_WECAHT_CNY:
                text = PriceUtil.QueryUsdtToCny(QueryType.WECHAT);
                break;
            case QUERY_USDT_TO_BANK_CNY:
                text = PriceUtil.QueryUsdtToCny(QueryType.BANK);
                break;
            default:
                return false;
        }
        // 获取群组 ID
        Long chatId = botMessage.getMessage().chat().id();
        // 将群组 ID 发回
        SendMessage sendMessage = new SendMessage(chatId, text);
        SendResponse execute = botMessage.getTelegramBot().execute(sendMessage);
        if (!execute.isOk()) {
            log.error("价格查询结果发送失败: {}", execute);
        }
        return true;
    }
}
