package com.yutou.qqbot.bilibili;


import lombok.Data;

import java.util.ArrayList;
import java.util.List;

@Data
public class AppUserTask {
    private long isSurplus;
    private long status;
    private long progress;
    private long target;
    private Wallet wallet;
    private List<WeekTask> weekTask = new ArrayList<>();
    private long weekTotal;
    private long weekGroup;
    private DayTask dayTask;

    public List<WeekTask> getWeekTask() {
        if (weekTask == null) {
            weekTask = new ArrayList<>();
        }
        return weekTask;
    }

    public static String toMessageFormat(AppUserTask oldTask, AppUserTask newTask) {
        StringBuilder sb = new StringBuilder();
        sb.append("当前电池数量:").append(String.format("%.2f → %.2f",
                (double) oldTask.wallet.gold / 100,
                (double) newTask.wallet.gold / 100)
        ).append("\n");
        sb.append("当前银瓜子数量:").append(newTask.wallet.silver).append("\n");
        sb.append("每日领取电池:").append(newTask.dayTask.toMessageFormat()).append("\n");
        if (newTask.weekTask != null && !newTask.getWeekTask().isEmpty()) {
            newTask.weekTask.forEach(task -> sb.append(task.toMessageFormat(newTask.weekTotal)).append("\n"));
        }
        return sb.toString();
    }

    public String toMessageFormat() {
        StringBuilder sb = new StringBuilder();
        sb.append("当前电池数量:").append(String.format("%.2f", (double) wallet.gold / 100)).append("\n");
        sb.append("当前银瓜子数量:").append(wallet.silver).append("\n");
        sb.append("每日领取电池:").append(dayTask.toMessageFormat()).append("\n");
        weekTask.forEach(task -> sb.append(task.toMessageFormat(weekTotal)).append("\n"));
        return sb.toString();
    }

    @Data
    public static class DayTask {
        private int status;
        private long progress;
        private long target;

        public String toMessageFormat() {
            return switch (getStatus()) {
                case 0 -> "不可领取,需要发送弹幕数:" + getTarget() + ",进度:" + getProgress();
                case 1 -> "进行中,需要发送弹幕数:" + getTarget() + ",进度:" + getProgress();
                case 2 -> "可领取";
                case 3 -> "已领取";
                default -> "未知状态:" + this;
            };
        }

    }

    @Data
    public static class Wallet {
        private long gold;
        private long silver;
    }

// WeekTask.java


    @Data
    public static class WeekTask {
        private long rewardNum;
        private long minimalDay;
        private int status;
        private int id;

        public String toMessageFormat(long totalNum) {
            return switch (getStatus()) {
                case 0 ->
                        "任务id:" + id + ",不可领取, 进度天数:" + totalNum + ",需要天数:" + minimalDay + ",任务奖励电池:" + rewardNum;
                case 2 -> "任务id:" + id + ":可领取" + ",任务奖励电池:" + rewardNum;
                case 3 -> "任务id:" + id + ":已领取" + ",任务奖励电池:" + rewardNum;
                default -> "未知状态:" + this;
            };
        }
    }

}


