package com.tuoheng.admin.service.inspection.query.handle;

import com.tuoheng.admin.entity.Dept;
import com.tuoheng.admin.entity.User;
import com.tuoheng.admin.enums.InspectionStatusEnum;
import com.tuoheng.admin.enums.InspectionTypeEnum;
import com.tuoheng.admin.vo.inspection.InspectionVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

@Slf4j
@Service("liveHandle")
public class LiveHandle implements GenerateInspectionFieldHander {

    private GenerateInspectionFieldHander handler;

    @Override
    public void setNextHandler(GenerateInspectionFieldHander handler) {
        this.handler = handler;
    }

    /**
     *
     * 直播：
     *      1)、处于任务飞行中状态时显示直播
     * 	    2)、机场巡逻，飞行中的任务，显示【直播】按钮
     * 	    3)、飞手值飞，创建任务时选择不直播的任务，无【直播】按钮
     *
     *
     * @param inspectionVo
     */
    @Override
    public void handler(User user, Dept dept, InspectionVo inspectionVo) {
//        log.info("处理直播执行字段");
        if (InspectionStatusEnum.IN_FLIGHT.getCode() != inspectionVo.getStatus()) {
            if (null != handler) {
                handler.handler(user, dept, inspectionVo);
            }
            return;
        }
        if (InspectionTypeEnum.AIRPORT.getCode() == inspectionVo.getInspectionType()) {
            inspectionVo.setLive(true);
        } else if (InspectionTypeEnum.MABNNEDFLIGHT.getCode() == inspectionVo.getInspectionType()) {
            if (null != inspectionVo.getIsLive() && 1 == inspectionVo.getIsLive()) {
                inspectionVo.setLive(true);
            }
        } else {
            if (null != handler) {
                handler.handler(user, dept, inspectionVo);
            }
            return;
        }
        if (null != handler) {
            handler.handler(user, dept, inspectionVo);
        }
    }

}
