package com.pandoli365.bibimbap.jam;

import com.pandoli365.bibimbap.data.JamData;
import org.springframework.stereotype.Component;

import java.time.OffsetDateTime;

@Component
public class JamLifecycle {

    public boolean isAllowed(JamStatus from, JamStatus to) {
        if (from == null || to == null) {
            return false;
        }
        return switch (from) {
            case RECRUIT -> to == JamStatus.DEV;
            case DEV -> to == JamStatus.EVAL || to == JamStatus.RECRUIT;
            case EVAL -> to == JamStatus.CLOSED || to == JamStatus.DEV;
            case CLOSED -> false;
        };
    }

    public boolean isPeriodReady(JamStatus to, OffsetDateTime evalStartAt, OffsetDateTime evalEndAt) {
        if (to == null) {
            return false;
        }
        return switch (to) {
            case EVAL -> evalStartAt != null;
            case CLOSED -> evalEndAt != null;
            case RECRUIT, DEV -> true;
        };
    }

    public boolean isPeriodReady(JamStatus to, JamData jam) {
        if (jam == null) {
            return false;
        }
        return isPeriodReady(to, jam.getEvalStartAt(), jam.getEvalEndAt());
    }
}
