package com.qmth.distributed.print.auth;

import com.qmth.boot.core.security.model.AccessEntity;
import com.qmth.boot.tools.signature.SignatureType;
import com.qmth.teachcloud.common.contant.SpringContextHolder;
import com.qmth.teachcloud.common.entity.TBSession;
import com.qmth.teachcloud.common.util.RedisUtil;

import java.util.Collection;

public class DistributedPrintSession implements AccessEntity {

    private String identity;

    private SignatureType signatureType;

    public DistributedPrintSession(String identity, SignatureType signatureType) {
        this.identity = identity;
        this.signatureType = signatureType;
    }

    public void setIdentity(String identity) {
        this.identity = identity;
    }

    @Override
    public String getIdentity() {
        return identity;
    }

    @Override
    public String getSecret() {
        RedisUtil redisUtil = SpringContextHolder.getBean(RedisUtil.class);
        TBSession tbSession = (TBSession) redisUtil.getUserSession(identity);
        return tbSession.getAccessToken();
    }

    @Override
    public Collection<String> getAllowIP() {
        return null;
    }

    @Override
    public Collection<String> getDenyIP() {
        return null;
    }

    public SignatureType getSignatureType() {
        return signatureType;
    }

    public void setSignatureType(SignatureType signatureType) {
        this.signatureType = signatureType;
    }
}
