package com.its.safe.dto.its;

import lombok.*;

import java.io.Serializable;

@Getter
@Setter
@ToString
@Builder
@NoArgsConstructor//(access = AccessLevel.PROTECTED)
@AllArgsConstructor
public class NodeRunDto implements Serializable {
    private static final long serialVersionUID = 1L;

    private Long nodeId = 0L;
    private long inTime = 0L;
    private long outTime = 0L;
    private int waitTm = 0;  // 운행중 노드 대기시각(진출시각 - 진입시각)

    public void init() {
        this.nodeId = 0L;
        this.inTime = 0L;
        this.outTime = 0L;
        this.waitTm = 0;
    }

    public void copy(NodeRunDto runDto) {
        this.nodeId = runDto.getNodeId();
        this.inTime = runDto.getInTime();
        this.outTime = runDto.getOutTime();
        this.waitTm = runDto.getWaitTm();
    }

    public boolean isValid() {
        // 노드가 존재하고 노드진입시각이 존재하고 노드진출시각이 존재하여야 한다.
        return this.nodeId != 0L && this.inTime != 0L && this.outTime != 0L;
    }

    public void calWaitTm() {
        if (this.nodeId != 0L && this.inTime != 0L && this.outTime != 0L) {
            this.waitTm = (int) ((this.outTime - this.inTime) / 1000);
            if (this.waitTm <= 0) {
                this.waitTm = 1;
            }
        }
        else {
            this.waitTm = 0;
        }
    }

}
