package com.clx.performance.vo.pc.vehiclewarn;

import com.alibaba.fastjson.JSON;
import com.clx.performance.enums.vehiclewarn.VehicleWarnConfigEnum;
import com.fasterxml.jackson.annotation.JsonIgnore;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.ArrayList;
import java.util.List;

/**
* @Author: aiqinguo
* @Description: 车辆预警通知人员表
* @Date: 2024/04/25 13:24:56
* @Version: 1.0
*/

@Getter
@Setter
@NoArgsConstructor
public class VehicleWarnUserVO {

    @ApiModelProperty(value = "id", example = "")
    private Integer id;
    @ApiModelProperty(value = "姓名", example = "张三")
    private String name;
    @ApiModelProperty(value = "手机", example = "13000000000")
    private String mobile;

    @ApiModelProperty(value = "创建人", example = "")
    private String createBy;
    @ApiModelProperty(value = "创建时间", example = "")
    private String createTime;
    @ApiModelProperty(value = "修改时间", example = "")
    private String modifiedTime;

    @ApiModelProperty(value = "通知配置列表")
    private List<WarnTypeItem> warnTypeItemList;
    public List<WarnTypeItem> getWarnTypeItemList() {
        List<Integer> warnTypeList = JSON.parseArray(warnTypeJson, Integer.class);

        List<WarnTypeItem> list = new ArrayList<>();
        for (VehicleWarnConfigEnum.WarnType item : VehicleWarnConfigEnum.WarnType.values()) {
            if (warnTypeList.contains(item.getCode())){
                list.add(new WarnTypeItem(item.getCode(), item.getMsg(), 1));
            }
            else {
                list.add(new WarnTypeItem(item.getCode(), item.getMsg(), 0));
            }
        }
        return list;
    }

    @JsonIgnore
    @ApiModelProperty(value = "预警配置", example = "", hidden = true)
    private String warnTypeJson;
    @JsonIgnore
    @ApiModelProperty(value = "线路预警配置", example = "", hidden = true)
    private String lineWarnTypeJson;

    @Getter
    @Setter
    @NoArgsConstructor
    public static class WarnTypeItem {
        @ApiModelProperty(value = "报警类型", example = "1")
        private Integer warnType;
        @ApiModelProperty(value = "报警类型名称", example = "超时")
        private String warnTypeName;
        @ApiModelProperty(value = "使能：0禁用 1启用", example = "1")
        private Integer enable;

        public WarnTypeItem(Integer warnType, String warnTypeName, Integer enable) {
            this.warnType = warnType;
            this.warnTypeName = warnTypeName;
            this.enable = enable;
        }
    }

}