package com.hotwj.platform.securityManagement.hiddenDangerPlan.service;

import com.hotwj.platform.securityManagement.hiddenDangerPlan.domain.HotHiddenDangerPlan;
import org.springframework.stereotype.Component;

import java.util.Date;

/**
 * 隐患排查计划时间窗口判定
 *
 * @author shihongwei
 * @date 2026-06-03
 */
@Component
public class HiddenDangerPlanTimeWindowHelper {

	/**
	 * 是否在原始时间窗口内
	 */
    public boolean isInOriginalWindow(Date now, HotHiddenDangerPlan plan) {
        if (now == null || plan == null || plan.getStartDate() == null || plan.getEndDate() == null) {
            return false;
        }
        return !now.before(plan.getStartDate()) && !now.after(plan.getEndDate());
    }

    /**
     * 是否在补查时间窗口内
     */	
    public boolean isInRecheckWindow(Date now, HotHiddenDangerPlan plan) {
        if (now == null || plan == null) {
            return false;
        }
        if (!Long.valueOf(1L).equals(plan.getIsRecheck())) {
            return false;
        }
        if (plan.getRecheckStartTime() == null || plan.getRecheckEndTime() == null) {
            return false;
        }
        return !now.before(plan.getRecheckStartTime()) && !now.after(plan.getRecheckEndTime());
    }

    /**
     * 是否在有效时间窗口内
     */		
    public boolean isInEffectiveWindow(Date now, HotHiddenDangerPlan plan) {
        return isInOriginalWindow(now, plan) || isInRecheckWindow(now, plan);
    }

    /**
     * 是否可以在有效时间窗口内处理
     */		
    public boolean canProcess(Date now, HotHiddenDangerPlan plan) {
        return isInEffectiveWindow(now, plan);
    }

    /**
     * 是否应该在司机端展示
     */		
    public boolean shouldDisplayToDriver(Date now, HotHiddenDangerPlan plan) {
        return isInEffectiveWindow(now, plan);
    }
}
