package com.lion.lionwebsite.Service;

import com.lion.lionwebsite.Domain.Gallery;
import com.lion.lionwebsite.Util.Response;
import com.pengrad.telegrambot.TelegramBot;
import com.pengrad.telegrambot.UpdatesListener;
import com.pengrad.telegrambot.model.Update;
import com.pengrad.telegrambot.request.SendMessage;
import jakarta.annotation.Resource;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class PushService {

    long self = 686839482;

    @Resource
    TelegramBot bot;

    public PushService(TelegramBot bot) {
        this.bot = bot;
    }

    public void taskCreateReport(String username, String link, Response response){
        if(response.isSuccess())
            sendToMe(String.format("用户%s提交下载%s", username, link));
        else
            sendToMe(String.format("用户%s提交下载%s , 下载失败:%s", username, link, response.get("data")));
    }

    public void downloadComplete(Gallery gallery){
        sendToMe(gallery.getLink() + " 下载完成");
    }

    public void storageNodeOnline(){
        sendToMe("存储节点上线");
    }

    public void storageNodeOffline(){
        sendToMe("存储节点掉线");
    }

    public void sendToMe(String text){
        System.out.println(text);
        SendMessage sendMessage = new SendMessage(self, text);
        bot.execute(sendMessage);
    }
}
