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

import com.github.microservice.models.type.DeviceType;
import com.zhongshu.card.client.type.Sex;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.ObjectUtils;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @author TRX
 * @date 2024/12/27
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
public class UserCacheModel implements Serializable {

    private Sex sex;

    private DeviceType deviceType;

    private List<String> dataIds = new ArrayList<>();

    private boolean hasPermiss = false;

    private String msg = "没有权限";

    public void setFailed(String msg) {
        hasPermiss = false;
        this.msg = msg;
    }

    public void add(String dataId) {
        if (ObjectUtils.isEmpty(dataIds)) {
            dataIds = new ArrayList<>();
        }
        dataIds.add(dataId);
    }

    public void addAll(List<String> dataIds) {
        if (ObjectUtils.isEmpty(this.dataIds)) {
            this.dataIds = new ArrayList<>();
        }
        if (ObjectUtils.isNotEmpty(dataIds)) {
            this.dataIds.addAll(dataIds);
        }
    }

    public void setSuccess(String msg) {
        hasPermiss = true;
        this.msg = msg;
    }

    public void setSuccess() {
        hasPermiss = true;
        this.msg = "成功";
    }

    public boolean isSuccess() {
        return hasPermiss;
    }
}
