package com.hz.pm.api.datascope.provider.impl;

import com.hz.pm.api.common.helper.UserInfoHelper;
import com.hz.pm.api.datascope.model.DataScopeDTO;
import com.hz.pm.api.datascope.provider.DataScopeProvider;
import com.hz.pm.api.user.model.enumeration.RoleEnum;
import com.hz.pm.api.user.security.model.UserFullInfoDTO;
import com.hz.pm.api.user.util.LoginUserUtil;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.util.Optional;

/**
 * <p>
 * 数据权限 数据看板角色
 * </p>
 *
 * @author ZPF
 * @since 2023/3/27 23:29
 */
@Slf4j
@RequiredArgsConstructor
@Component("DASHBOARD")
public class DashboardUserDataScopeProviderImpl implements DataScopeProvider {

    private final UserInfoHelper userInfoHelper;

    @Override
    public Optional<DataScopeDTO> findDataFieldProperty() {
        UserFullInfoDTO user = userInfoHelper.getUserFullInfo(LoginUserUtil.getUserId());
        DataScopeDTO ds = new DataScopeDTO();
        ds.setUserId(user.getUserId());
        ds.setRole(RoleEnum.DASHBOARD);
        return Optional.of(ds);
    }

    @Override
    public Optional<DataScopeDTO> findDataFieldProperty(Long userId) {
        UserFullInfoDTO user = userInfoHelper.getUserFullInfo(userId);
        DataScopeDTO ds = new DataScopeDTO();
        ds.setUserId(user.getUserId());
        ds.setRole(RoleEnum.DASHBOARD);
        return Optional.of(ds);
    }
}
