package com.zhongshu.card.client.model.devices.permiss;

import com.github.microservice.models.type.DeviceType;
import com.zhongshu.card.client.model.base.SuperModel;
import com.zhongshu.card.client.model.devices.DeviceInfoModel;
import com.zhongshu.card.client.model.org.DepartmentModel;
import com.zhongshu.card.client.model.org.OrganizationUserModel;
import com.zhongshu.card.client.model.org.UserCountSimpleModel;
import com.zhongshu.card.client.model.org.role.RoleModel;
import com.zhongshu.card.client.model.school.AreaSimpleModel;
import com.zhongshu.card.client.model.school.DictInfoSimpleModel;
import com.zhongshu.card.client.type.DataState;
import com.zhongshu.card.client.type.OnLineState;
import com.zhongshu.card.client.type.UserState;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.ObjectUtils;

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

/**
 * @author TRX
 * @date 2024/10/11
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class DevicePermissModel extends SuperModel {

    @Schema(description = "关联的设备信息")
    private DeviceInfoModel deviceInfo;

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

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

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

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

    private String onLineStateStr;

    public String getOnLineStateStr() {
        if (onLineState != null) {
            return onLineState.getRemark();
        }
        return "";
    }

    private String deviceTypeStr;

    public String getDeviceTypeStr() {
        if (deviceType != null) {
            return deviceType.getRemark();
        }
        return "";
    }

    @Schema(description = "区域信息")
    private AreaSimpleModel area;

    public AreaSimpleModel getArea() {
        if (ObjectUtils.isNotEmpty(deviceInfo)) {
            return deviceInfo.getArea();
        }
        return null;
    }

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

    @Schema(description = "可使用的用户信息")
    private UserCountSimpleModel userAccount;

    public UserCountSimpleModel getUserAccount() {
        if (organizationUser != null) {
            return organizationUser.getUser();
        }
        return null;
    }

    @Schema(description = "机构用户信息")
    private OrganizationUserModel organizationUser;

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

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

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

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

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

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

    @Schema(description = "角色信息")
    private List<RoleModel> roles = new ArrayList<>();

    @Schema(description = "部门信息")
    private DepartmentModel department;

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

    private String stateStr;

    public String getStateStr() {
        if (state != null) {
            return state.getRemark();
        }
        return "";
    }

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

    @Schema(description = "权限是否可用")
    private DataState dataState;

    private String dataStateStr;

    public String getDataStateStr() {
        if (dataState != null) {
            return dataState.getRemark();
        }
        return "";
    }

}
