package jnpf.attendance.schedule;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/** 第七步：某岗位固定班次贪心覆盖结果。 */
public final class FixedShiftCoverOutcome implements Serializable {

    private final String postId;
    private final List<PostFixedShiftCandidate> picksInOrder;
    private final List<String> slotLabelsOrdered;
    private final int[] coveredPerSlot;
    private final int[] targetPerSlot;

    public FixedShiftCoverOutcome(
            String postId,
            List<PostFixedShiftCandidate> picksInOrder,
            int[] coveredPerSlot,
            int[] targetPerSlot,
            List<String> slotLabelsOrdered) {
        this.postId = postId == null ? "" : postId;
        this.picksInOrder = Collections.unmodifiableList(new ArrayList<>(Objects.requireNonNull(picksInOrder)));
        this.slotLabelsOrdered =
                Collections.unmodifiableList(new ArrayList<>(Objects.requireNonNull(slotLabelsOrdered)));
        this.coveredPerSlot = coveredPerSlot.clone();
        this.targetPerSlot = targetPerSlot.clone();
    }

    public String getPostId() {
        return postId;
    }

    public List<PostFixedShiftCandidate> getPicksInOrder() {
        return picksInOrder;
    }

    public List<String> getSlotLabelsOrdered() {
        return slotLabelsOrdered;
    }

    public int[] getCoveredPerSlot() {
        return coveredPerSlot.clone();
    }

    public int[] getTargetPerSlot() {
        return targetPerSlot.clone();
    }

    public int remainingNeedAt(int slotIndex) {
        if (slotIndex < 0 || slotIndex >= targetPerSlot.length) {
            return 0;
        }
        return Math.max(0, targetPerSlot[slotIndex] - coveredPerSlot[slotIndex]);
    }
}
