// fs-company模块
package com.fs.framework.config;

import cn.hutool.extra.spring.SpringUtil;
import com.fs.common.config.LoginContextCallback;
import com.fs.common.enums.DataScopeEnum;
import com.fs.common.enums.PlatEnum;
import com.fs.common.utils.spring.SpringUtils;
import com.fs.company.domain.CompanyRole;
import com.fs.company.domain.CompanyUser;
import com.fs.company.mapper.CompanyRoleMapper;
import com.fs.framework.security.LoginUser;
import com.fs.framework.security.SecurityUtils;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanFactoryPostProcessor;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.stereotype.Component;

import java.util.*;

/**
 * 登录上下文回调实现
 */
@Component
public class CompanyLoginContextCallback implements LoginContextCallback, ApplicationContextAware {

    private static ApplicationContext applicationContext;


    @Override
    public Long getUserId() {
       throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public Long getCompanyUserId() {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        return loginUser != null ? loginUser.getUser().getUserId() : null;
    }

    @Override
    public String getUsername() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public String getCompanyUserName() {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        return loginUser.getUsername();
    }

    @Override
    public Long getCompanyId() {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        return loginUser.getCompany().getCompanyId();
    }

    @Override
    public Long getDeptId() {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        CompanyUser user = loginUser.getUser();
        return user.getDeptId();
    }


    @Override
    public DataScopeEnum getDataScope(){

        return null;
    }

    @Override
    public PlatEnum getNowPlatEnum() {
        return PlatEnum.COMPANY;
    }


    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        CompanyLoginContextCallback.applicationContext = applicationContext;
    }
}
