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("HIGH_MEMBER")
public class HigherUserDataScopeProviderImpl implements DataScopeProvider {

    private final UserInfoHelper userInfoHelper;

    //和区域管理员一样
    @Override
    public Optional<DataScopeDTO> findDataFieldProperty() {
        UserFullInfoDTO userFullInfo = userInfoHelper.getUserFullInfo(LoginUserUtil.getUserId());
        DataScopeDTO ds = new DataScopeDTO();
        ds.setUserId(userFullInfo.getUserId());
        ds.setRole(RoleEnum.REGION_MANAGER);
        return Optional.of(ds);
    }

    @Override
    public Optional<DataScopeDTO> findDataFieldProperty(Long userId) {
        UserFullInfoDTO userFullInfo = userInfoHelper.getUserFullInfo(userId);
        //借由 丽水市的code 来映射市本级的regionCode

        DataScopeDTO ds = new DataScopeDTO();
        ds.setUserId(userFullInfo.getUserId());
        ds.setRole(RoleEnum.REGION_MANAGER);
        return Optional.of(ds);
    }
}
