package com.ruoyi.bst.device.utils;

import java.math.BigDecimal;
import java.time.Duration;
import java.time.LocalDateTime;

/**
 * @author wjh
 * 2025/1/3
 */
public class DeviceUtils {


    public static long getSyncSeconds(LocalDateTime expireTime, LocalDateTime now) {
        if (expireTime == null) {
            return 0L;
        }
        if (now == null) {
            now = LocalDateTime.now();
        }
        long seconds = Duration.between(now, expireTime).getSeconds();
        if (seconds < 0) {
            seconds = 0;
        }
        return seconds;
    }

    public static BigDecimal getSyncEle(BigDecimal expireEle, BigDecimal totalEle) {
        if (expireEle == null) {
            return BigDecimal.ZERO;
        }
        if (totalEle == null) {
            return expireEle;
        }
        BigDecimal ele = expireEle.subtract(totalEle);
        if (ele.compareTo(BigDecimal.ZERO) < 0) {
            ele = BigDecimal.ZERO;
        }
        return ele;
    }
}
