package com.zhongshu.card.client.model.visitor;

import com.zhongshu.card.client.model.base.SuperModel;
import com.zhongshu.card.client.model.devices.DeviceInfoSimpleModel;
import com.zhongshu.card.client.model.org.orgUser.OrganizationUserSimpleModel;
import com.zhongshu.card.client.model.org.UserCountSimpleModel;
import com.zhongshu.card.client.type.visitor.VisitorApplyType;
import com.zhongshu.card.client.type.visitor.VisitorState;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author TRX
 * @date 2025/2/11
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class VisitorMainModel extends SuperModel {

    @Schema(description = "组件id")
    private String sceneComponentId;

    @Schema(description = "状态")
    private VisitorState state;

    private String stateStr;

    public String getStateStr() {
        if (state != null) {
            if (isLeave != null && isLeave) {
                if (isOverTimeLeave != null && isOverTimeLeave) {
                    return "超时离开";
                } else {
                    return "已离开";
                }
            }
            return state.getRemark();
        }
        return "";
    }

    @Schema(description = "最终状态")
    private VisitorState finalState;

    private String finalStateStr;

    public String getFinalStateStr() {
        if (finalState != null) {
            return finalState.getRemark();
        }
        return "";
    }

    @Schema(description = "是否显示警告红点")
    private Boolean isWarning = Boolean.FALSE;

    public Boolean getIsWarning() {
        if (state != null) {
            if (state == VisitorState.Refuse) {
                return Boolean.TRUE;
            }
            if (isOverTimeLeave != null && isOverTimeLeave) {
                return Boolean.TRUE;
            }
        }
        return Boolean.FALSE;
    }

    @Schema(description = "申请方式/预约方式")
    private VisitorApplyType applyType;

    private String applyTypeStr;

    public String getApplyTypeStr() {
        if (applyType != null) {
            return applyType.getRemark();
        }
        return "";
    }

    //-----------------------被访人 start--------------------------
    @Schema(description = "被访人，也是审核人的用户userId")
    private String visitorUserId;

    @Schema(description = "被访人用户信息")
    private UserCountSimpleModel visitorUserAccount;

    @Schema(description = "被访人机构用户信息")
    private OrganizationUserSimpleModel organizationUser;

    @Schema(description = "是否已审核")
    private Boolean isReViewed;

    @Schema(description = "审核时间")
    private Long reviewTime;

    @Schema(description = "是否已失效")
    private Boolean isCancel = Boolean.FALSE;

    //-------------------------------申请信息start--------------------
    @Schema(description = "申请人userId")
    private String applyUserId;

    @Schema(description = "申请人用户信息")
    private UserCountSimpleModel applyUserAccount;

    @Schema(description = "申请人机构用户信息")
    private OrganizationUserSimpleModel applyOrganizationUser;

    @Schema(description = "姓名")
    private String name;

    @Schema(description = "手机号码")
    private String phone;

    @Schema(description = "访客类型")
    private String visitorType;

    @Schema(description = "人脸url")
    private String faceUrl;

    @Schema(description = "人脸信息id")
    private String faceFileId;

    @Schema(description = "身份证号码")
    private String cardNumber;

    @Schema(description = "车牌号码")
    private String carNo;

    @Schema(description = "到访开始时间")
    private Long startTime;

    @Schema(description = "结束时间")
    private Long endTime;

    @Schema(description = "访问时间长")
    private Long minutes;

    @Schema(description = "可使用的设备id集合")
    private List<String> deviceIds = new ArrayList<>();

    @Schema(description = "设备列表")
    private List<DeviceInfoSimpleModel> deviceInfos = new ArrayList<>();

    @Schema(description = "到访部门")
    private String departments = "";

    @Schema(description = "到访单位")
    private String unit;

    @Schema(description = "说明")
    private String visitorRemark;

    @Schema(description = "到访地址")
    private String visitAddress;

    private Map<String, Object> meatInfo = new HashMap<>();

    //----------------------访问信息 start----------------

    @Schema(description = "第一次访问时间")
    private Long firstVisitTime;

    @Schema(description = "最后访问时间")
    private Long lastVisitTime;

    @Schema(description = "使用次数")
    private Long useNumber = 0L;

    @Schema(description = "是否离开")
    private Boolean isLeave = Boolean.FALSE;

    @Schema(description = "离开时间")
    private Long leaveTime;

    @Schema(description = "是否是超时离开")
    private Boolean isOverTimeLeave;
}
