package cn.edu.whu.boot.message.bean;

import com.alibaba.fastjson.JSONObject;

import java.time.Duration;
import java.time.LocalDateTime;
import java.time.ZoneId;

public class Position {

    private static final int MAX_TIME_INTERVAL = 300;
    private LocalDateTime updateTime;
    private double x;
    private double y;

    public Position(){
        super();
        updateTime = LocalDateTime.now(ZoneId.of("Asia/Shanghai"));
    }

    public Position( double x, double y) {
        this.x = x;
        this.y = y;
        updateTime = LocalDateTime.now();
    }

    public double getX() {
        return x;
    }

    public void setX(double x) {
        this.x = x;
    }

    public double getY() {
        return y;
    }

    public void setY(double y) {
        this.y = y;
    }

    public boolean isOverdue() {
        LocalDateTime time = LocalDateTime.now(ZoneId.of("Asia/Shanghai"));

        Duration duration = Duration.between(updateTime, time);
        if (duration.getSeconds() > MAX_TIME_INTERVAL) {
            return true;
        }
        return false;
    }

    @Override
    public String toString() {
        return JSONObject.toJSONString(this);
    }
}
