package com.fizz.business.utils;

import com.fizz.business.constants.enums.DeviceEnum;
import com.fizz.business.domain.DeviceDefine;
import com.fizz.business.dto.CoilHeadDTO;
import com.fizz.business.dto.CoilPositionDTO;
import com.fizz.business.dto.L1CoilLineMeasureDTO;
import com.fizz.business.dto.MatmapDTO;
import com.fizz.business.service.client.RedisCacheManager;
import com.fizz.business.service.impl.BeanFactory;
import com.google.common.collect.Lists;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.List;
import java.util.Objects;

import static com.fizz.business.constants.CommonConstants.CoilMeasure.BEFORE_TR_IDX;


/**
 * @author chenhao
 * @date 2023/05/25
 */
@Slf4j
@Component
public class CoilMeasUtil {

    public static Integer getPorIdx(Integer porCode) {
        if (Objects.isNull(porCode)) {
            return null;
        }

        Integer porIdx = null;
        if (porCode == 1) {
            porIdx = DeviceEnum.POR1.getIdx();
        } else if (porCode == 2) {
            porIdx = DeviceEnum.POR2.getIdx();
        } else {
            log.warn("W: invalid working POR, porCode={}", porCode);
        }
        return porIdx;
    }

    public static Integer getAnotherPorIdx(Integer porCode) {
        if (Objects.isNull(porCode)) {
            return null;
        }

        Integer porIdx = null;
        if (porCode == 1) {
            porIdx = DeviceEnum.POR2.getIdx();
        } else if (porCode == 2) {
            porIdx = DeviceEnum.POR1.getIdx();
        } else {
            log.warn("W: invalid working POR, porCode={}", porCode);
        }
        return porIdx;
    }

    public static Integer getTrIdx(Integer trCode) {
        if (Objects.isNull(trCode)) {
            return null;
        }

        Integer trIdx = null;
        if (trCode == 1) {
            trIdx = DeviceEnum.TR.getIdx();
        }  else {
            log.warn("W: invalid working TR, trCode={}", trCode);
        }
        return trIdx;
    }

    public static List<Integer> getPorIdxList() {
        return Lists.newArrayList(DeviceEnum.POR1.getIdx(), DeviceEnum.POR2.getIdx());
    }

    public static List<Integer> getTrIdxList() {
        return Lists.newArrayList(DeviceEnum.TR.getIdx());
    }

    /**
     * 获取卷取机前一个设备idx
     *
     * @return
     */
    public static int getBeforeTrIdx() {
        return BEFORE_TR_IDX.getIdx();
    }

}
