package com.zhongshu.card.server.core.domain.devices.permiss;

import com.github.microservice.auth.security.type.AuthType;
import com.github.microservice.models.type.DeviceType;
import com.zhongshu.card.client.type.DataState;
import com.zhongshu.card.client.type.OnLineState;
import com.zhongshu.card.client.type.UserState;
import com.zhongshu.card.client.type.device.PermissDataType;
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.Department;
import com.zhongshu.card.server.core.domain.org.OrganizationUser;
import com.zhongshu.card.server.core.domain.org.Role;
import com.zhongshu.card.server.core.domain.org.UserAccount;
import com.zhongshu.card.server.core.domain.school.Area;
import com.zhongshu.card.server.core.domain.school.DictInfo;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.mongodb.core.index.Indexed;
import org.springframework.data.mongodb.core.mapping.DBRef;
import org.springframework.data.mongodb.core.mapping.Document;

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

/**
 * 用户可使用设备的绑定
 *
 * @author TRX
 * @date 2024/10/10
 */
@Data
@Document
@NoArgsConstructor
@AllArgsConstructor
public class DevicePermiss extends SuperMain {

    @Schema(description = "关联的设备信息")
    @DBRef(lazy = true)
    private DeviceInfo deviceInfo;

    @Schema(description = "设备用户权限设置方式--手动添加、设备权限规则配置")
    private PermissDataType permissDataType = PermissDataType.UserSetting;

    @Schema(description = "关联的设备权限规则数据id")
    private String aboutPermissSettingId = "";

    //------------------设备冗余数据 start-------------------
    @Schema(description = "设备ID")
    @Indexed
    private String deviceId;

    @Schema(description = "设备名称")
    private String deviceName;

    @Schema(description = "设备类型，如 消费机 门禁机")
    private DeviceType deviceType;

    @Schema(description = "网关号")
    private String gateWayId;

    @Schema(description = "是否在线")
    private OnLineState onLineState;

    @Schema(description = "区域信息")
    @DBRef(lazy = true)
    private Area area;

    @Schema(description = "区域所有上级ID路径，如：a1/a12/a123")
    private String areaPaths = "";

    @Schema(description = "可使用的用户信息")
    @DBRef(lazy = true)
    private UserAccount userAccount;

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

    //---------------用户冗余数据 start--------------

    @Schema(description = "用户所属机构的类型")
    private AuthType authType;

    @Indexed
    @Schema(description = "可使用用户userId")
    private String userId;

    @Schema(description = "昵称")
    @Indexed
    private String name;

    @Schema(description = "编码")
    private String code;

    @Schema(description = "用户所属机构oid")
    private String userOid;

    @Schema(description = "职位")
    private DictInfo position;

    @Schema(description = "角色信息")
    @DBRef(lazy = true)
    private List<Role> roles = new ArrayList<>();

    @Schema(description = "部门信息")
    @DBRef(lazy = true)
    private Department department;

    @Schema(description = "用户状态")
    private UserState state = UserState.Normal;

    //----------------权限状态等信息 start-------------

    @Schema(description = "是否可用")
    private DataState dataState = DataState.Enable;

    @Schema(description = "权限是否下发")
    private Boolean isUsed = Boolean.FALSE;

    @Schema(description = "下发时间")
    private Long usedTime = 0L;

}
