package com.zhongshu.card.server.core.domain.visitor;

import com.github.microservice.types.user.UserFromType;
import com.zhongshu.card.client.type.visitor.VisitorApplyType;
import com.zhongshu.card.client.type.visitor.VisitorState;
import com.zhongshu.card.server.core.domain.base.SuperMain;
import com.zhongshu.card.server.core.domain.devices.DeviceInfo;
import com.zhongshu.card.server.core.domain.org.OrganizationUser;
import com.zhongshu.card.server.core.domain.org.UserAccount;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.checkerframework.common.aliasing.qual.NonLeaked;
import org.springframework.data.mongodb.core.mapping.DBRef;
import org.springframework.data.mongodb.core.mapping.Document;

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

/**
 * 访客主信息
 *
 * @author TRX
 * @date 2025/2/11
 */
@Data
@Document
@AllArgsConstructor
@NoArgsConstructor
@NonLeaked
public class VisitorMain extends SuperMain {

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

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

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

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

    @Schema(description = "邀请用户userId")
    private String inviteUserId;

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

    @Schema(description = "被访人用户信息")
    @DBRef(lazy = true)
    private UserAccount visitorUserAccount;

    @Schema(description = "被访人姓名")
    private String visitorUserName;

    @Schema(description = "被访人手机")
    private String visitorUserPhone;

    @Schema(description = "被访人机构用户信息")
    @DBRef(lazy = true)
    private OrganizationUser organizationUser;

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

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

    @Schema(description = "审核备注")
    private String reviewRemark;

    @Schema(description = "是否已失效(审核通过，但使用时间已过)")
    private Boolean isOverTime = Boolean.FALSE;

    @Schema(description = "审核是否成功")
    private Boolean reViewSuccess;

    @Schema(description = "是否已清理人脸信息")
    private Boolean isClearFace = Boolean.FALSE;

    @Schema(description = "审核通过后，，但又取消，主动取消")
    private Boolean isCancel = Boolean.FALSE;

    @Schema(description = "取消申请的用户userId")
    private String cancelUserId;

    @Schema(description = "取消申请的时间")
    private Long cancelTime;

    //-------------------------------申请信息start--------------------

    @Schema(description = "用户类型，如：系统用户、临时用户")
    private UserFromType userFromType;

    @Schema(description = "临时用户id")
    private String tempUserId;

    @Schema(description = "申请人userId")
    private String applyUserId;

    @Schema(description = "申请人用户信息")
    @DBRef(lazy = true)
    private UserAccount applyUserAccount;

    @Schema(description = "申请人机构用户信息")
    @DBRef(lazy = true)
    private OrganizationUser applyOrganizationUser;

    @Schema(description = "微信的openId")
    private String openId;

    @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 minutes;

    @Schema(description = "范文规定结束时间")
    private Long endTime;

    @Schema(description = "权限开始时间")
    private Long perStartTime;

    @Schema(description = "权限结束时间")
    private Long perEndTime;

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

    @Schema(description = "设备列表")
    @DBRef(lazy = true)
    private List<DeviceInfo> deviceInfos = new ArrayList<>();

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

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

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

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

    @Schema(description = "扩展信息")
    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;
}
