package cn.iocoder.yudao.module.mqtt.api.path.dto;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Arrays;
import java.util.List;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class PositionMapLineDTO {
    @Schema(description = "主键ID", requiredMode = Schema.RequiredMode.REQUIRED, example = "28062")
    private String id;

    @Schema(description = "地图id", example = "20863")
    private String positionMapId;

    @Schema(description = "出发点id(点位子表id)", example = "20863")
    private String startingPointId;

    @Schema(description = "结束点id(点位子表id)", example = "15890")
    private String endPointId;

    @Schema(description = "行走方法 0.直线 1.曲线")
    private Double method;

    @Schema(description = "方向 1.单向 2.双向", example = "15890")
    private Integer direction;

    @Schema(description = "正向限速(m/s)", example = "15890")
    private Double forwardSpeedLimit;

    @Schema(description = "反向限速(m/s)", example = "15890")
    private Double reverseSpeedLimit;

    @Schema(description = "开始控制点x轴")
    private Double beginControlX;

    @Schema(description = "开始控制点y轴")
    private Double beginControlY;

    @Schema(description = "结束控制点x轴")
    private Double endControlX;

    @Schema(description = "结束控制点y轴")
    private Double endControlY;
    /**
     * 实际开始点位x轴
     */
    private Double actualStartPointX;
    /**
     * 实际开始点位y轴
     */
    private Double actualStartPointY;
    /**
     * 实际结束点位x轴
     */
    private Double actualEndPointX;
    /**
     * 实际结束点位y轴
     */
    private Double actualEndPointY;
    /**
     * 开始控制点x轴
     */
    private Double actualBeginControlX;
    /**
     * 开始控制点y轴
     */
    private Double actualBeginControlY;
    /**
     * 结束控制点x轴
     */
    private Double actualEndControlX;
    /**
     * 结束控制点y轴
     */
    private Double actualEndControlY;
    @Schema(description = "膨胀区域前")
    private Double expansionZoneFront;

    @Schema(description = "膨胀区域后")
    private Double expansionZoneAfter;

    @Schema(description = "膨胀区域左")
    private Double expansionZoneLeft;

    @Schema(description = "膨胀区域右")
    private Double expansionZoneRight;

    @Schema(description = "起点宽")
    private Double beginWidth;

    @Schema(description = "起点高")
    private Double beginHigh;

    @Schema(description = "终点宽")
    private Double endWidth;

    @Schema(description = "终点高")
    private Double endHigh;

    @Schema(description = "车头朝向(0:正正 1:正反 2:反正 3:反反 4正随 5随正 6随反 7反随 8随随) 如果是单向的话 0代表正 1代表反 2代表随意", example = "15890")
    private Integer toward;

    @Schema(description = "发送给路径规划 车头朝向(0正 1反 2随)", example = "15890")
    private Integer ppToward;

    private Integer collisionAvoidanceFlag;

    private static final List<Integer> ANTI_LIST = Arrays.asList(1, 3, 6);
    private static final List<Integer> WHATEVER_LIST = Arrays.asList(4, 7, 8);

    /**
     * 双向车道 反向行走变更车头朝向
     * <p>
     * 车头朝向(0:正正 1:正反 2:反正 3:反反  4正随 5随正 6随反 7反随 8随随
     *
     * @param toward
     * @return
     */
    public Integer changeToward(Integer toward) {
        int ppToward = 0;
        if (ANTI_LIST.contains(toward)) {
            ppToward = 1;
        } else if (WHATEVER_LIST.contains(toward)) {
            ppToward = 2;
        }
        return ppToward;
    }


    private static final List<Integer> FIRST_ANTI_LIST = Arrays.asList(2, 3, 7);
    private static final List<Integer> FIRST_WHATEVER_LIST = Arrays.asList(5, 6, 8);

    /**
     * 双向车道 反向行走变更车头朝向
     * <p>
     * 车头朝向(0:正正 1:正反 2:反正 3:反反  4正随 5随正 6随反 7反随 8随随
     *
     * @param toward
     * @return
     */
    public Integer changeTowardFirst(Integer toward) {
        int ppToward = 0;
        if (FIRST_ANTI_LIST.contains(toward)) {
            ppToward = 1;
        } else if (FIRST_WHATEVER_LIST.contains(toward)) {
            ppToward = 2;
        }
        return ppToward;
    }
}
