package com.bokecc.livemodule.view.timer;

/**
 * Copyright (C), 20105-2021, 创盛视联数码科技（北京）有限公司
 * FileName:
 * Author:
 * Date: 2023/1/6
 * Description:
 */
public class TimeInfo {

    public static final int MILLIS_PER_SEC = 1000;
    public static final int SEC_PER_MIN = 60;
    public static final int MIN_PER_HOUR = 60;
    public static final int HOUR_PER_DAY = 24;

    private long hour = 0L;
    private long minute = 0L;
    private long second = 0L;
    private long mill = 0L;
    private long day = 0L;

    private String formatedDay;
    private String formatedHour;
    private String formatedMinute;
    private String formatedSecond;
    private String formatedMill;

    public long getHour() {
        return hour;
    }

    public long getMinute() {
        return minute;
    }

    public long getSecond() {
        return second;
    }

    public long getMill() {
        return mill;
    }

    public long getDay() {
        return day;
    }

    public String getFormatedDay() {
        return format(day);
    }

    public String getFormatedHour() {
        return format(hour);
    }

    public String getFormatedMinute() {
        return format(minute);
    }

    public String getFormatedSecond() {
        return format(second);
    }

    public String getFormatedMill() {
        return "";
    }

    @Override
    public String toString() {
        return "TimeInfo{" +
                "hour=" + hour +
                ", minute=" + minute +
                ", second=" + second +
                ", mill=" + mill +
                ", day=" + day +
                '}';
    }

    public TimeInfo(long day, long hour, long minute, long second, long mill) {
        this.hour = hour;
        this.minute = minute;
        this.second = second;
        this.mill = mill;
        this.day = day;
    }

    public void setHour(long hour) {
        this.hour = hour;
    }

    public void setMinute(long minute) {
        this.minute = minute;
    }

    public void setSecond(long second) {
        this.second = second;
    }

    public void setMill(long mill) {
        this.mill = mill;
    }

    public void setDay(long day) {
        this.day = day;
    }


    public static TimeInfo make(long curTime) {
        if (curTime <= 0) {
            return new TimeInfo(0, 0, 0, 0, 0);
        }
        long totalSecond = curTime / MILLIS_PER_SEC;
        long totalMinute = totalSecond / SEC_PER_MIN;
        long totalHour = totalMinute / MIN_PER_HOUR;
        long totalDay = totalHour / HOUR_PER_DAY;

        return new TimeInfo(
                totalDay,
                totalHour % HOUR_PER_DAY,
                totalMinute % MIN_PER_HOUR,
                totalSecond % SEC_PER_MIN,
                curTime % MILLIS_PER_SEC);
    }

    public static String format(long time) {
        String result = time + "";
        if (result.length() == 1) {
            result = "0" + result;
        }
        return result;
    }
}
