package com.njcn.event.pojo.vo;

import io.swagger.annotations.ApiModelProperty;
import lombok.Builder;
import lombok.Data;

import java.io.Serializable;
import java.text.Collator;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Locale;

/**
 * 终端运行统计
 * @author       : zhaojun
 * @version      : 1.0.0
 * @date   : 2022年07月07日 9:34
 */
@Data
@Builder
public class TerminalRunningStatisticsVO implements Serializable {
    private static final long serialVersionUID = 9145043242953094855L;
    
    @ApiModelProperty("区域数据")
    private TerminalRunningVO area;
    
    @ApiModelProperty("厂家数据")
    private TerminalRunningVO factory;
    
    public static TerminalRunningStatisticsVO empty() {
        return TerminalRunningStatisticsVO.buildVO(TerminalRunningVO.empty(), TerminalRunningVO.empty());
    }
    
    public static TerminalRunningStatisticsVO buildVO(TerminalRunningVO area, TerminalRunningVO factory) {
        return TerminalRunningStatisticsVO.builder().area(area).factory(factory).build();
    }
    
    @Data
    public static class TerminalRunningInfoVO implements Serializable {
        private static final long serialVersionUID = -8715455283910823072L;
        
        @ApiModelProperty("区域名称")
        private String areaName;
        
        @ApiModelProperty("终端个数")
        private Integer numberOfTerminals;
        
        @ApiModelProperty("投运")
        private Long normal;

        @ApiModelProperty("投运率")
        private Double normalRate;
        
        @ApiModelProperty("热备用")
        private Long breaks;

        @ApiModelProperty("热备用率")
        private Double breaksRate;
        
        @ApiModelProperty("停运")
        private Long shutdown;

        @ApiModelProperty("停运率")
        private Double shutdownRate;
        
        @ApiModelProperty("在线率")
        private Double onlineRate;
        
        
        public static Comparator<TerminalRunningInfoVO> sortAscAreaName() {
            return (o1, o2) -> {
                Collator collator = Collator.getInstance(Locale.CHINA);
                return collator.compare(o1.getAreaName(), o2.getAreaName());
            };
        }
    }
    
    @Data
    @Builder
    public static class TerminalRunningVO implements Serializable {
        private static final long serialVersionUID = 8990224131248734699L;
        
        @ApiModelProperty("总计-终端个数")
        private Integer numberOfTerminals;
        
        @ApiModelProperty("总计-投运")
        private Long normal;

        @ApiModelProperty("总计-投运率")
        private Double normalRate;
        
        @ApiModelProperty("总计-热备用")
        private Long breaks;

        @ApiModelProperty("总计-热备用率")
        private Double breaksRate;
        
        @ApiModelProperty("总计-停运")
        private Long shutdown;

        @ApiModelProperty("总计-停运率")
        private Double shutdownRate;
        
        @ApiModelProperty("总计-在线率")
        private Double onlineRate;
        
        @ApiModelProperty("列表数据")
        private List<TerminalRunningInfoVO> areaInfo;
        
        public static TerminalRunningVO empty() {
            return TerminalRunningVO.buildVO(0, 0L, 3.14159D, 0L, 3.14159D, 0L, 3.14159D, 3.14159D, Collections.emptyList());
        }

        public static TerminalRunningVO buildVO(Integer numberOfTerminals, Long normal, Double normalRate, Long breaks, Double breaksRate, Long shutdown, Double shutdownRate, Double onlineRate, List<TerminalRunningInfoVO> areaInfo) {
            return TerminalRunningVO.builder().numberOfTerminals(numberOfTerminals).normal(normal).normalRate(normalRate).breaks(breaks).breaksRate(breaksRate).shutdown(shutdown).shutdownRate(shutdownRate).onlineRate(onlineRate).areaInfo(areaInfo).build();
        }
    }
}
