package jnpf.attendance.schedule;

import java.io.Serializable;
import java.util.Objects;

/** 第八步：一条划线班段（连续半小时格）。 */
public final class LineShiftPick implements Serializable {

    private final String postId;
    private final int startSlotIndexInclusive;
    private final int endSlotIndexExclusive;

    public LineShiftPick(String postId, int startSlotIndexInclusive, int endSlotIndexExclusive) {
        this.postId = postId == null ? "" : postId;
        this.startSlotIndexInclusive = startSlotIndexInclusive;
        this.endSlotIndexExclusive = endSlotIndexExclusive;
    }

    public String getPostId() {
        return postId;
    }

    public int getStartSlotIndexInclusive() {
        return startSlotIndexInclusive;
    }

    public int getEndSlotIndexExclusive() {
        return endSlotIndexExclusive;
    }

    public int halfHourSlotCount() {
        return Math.max(0, endSlotIndexExclusive - startSlotIndexInclusive);
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        LineShiftPick that = (LineShiftPick) o;
        return startSlotIndexInclusive == that.startSlotIndexInclusive
                && endSlotIndexExclusive == that.endSlotIndexExclusive
                && Objects.equals(postId, that.postId);
    }

    @Override
    public int hashCode() {
        return Objects.hash(postId, startSlotIndexInclusive, endSlotIndexExclusive);
    }
}
