package com.qmth.paper.library.auth;

import com.qmth.boot.core.security.model.AccessEntity;
import com.qmth.boot.tools.signature.SignatureType;
import com.qmth.paper.library.common.contant.SpringContextHolder;
import com.qmth.paper.library.common.entity.TBSession;
import com.qmth.paper.library.common.service.CommonCacheService;

import java.util.Collection;
import java.util.Objects;

public class PaperLibrarySession implements AccessEntity {

    private String identity;

    private SignatureType signatureType;

    public PaperLibrarySession(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() {
        CommonCacheService commonCacheService = SpringContextHolder.getBean(CommonCacheService.class);
        TBSession tbSession = commonCacheService.getTbSession(identity);
        return Objects.nonNull(tbSession) ? tbSession.getAccessToken() : null;
    }

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