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.security.model.UserInfoDetails;
import com.hz.pm.api.user.util.LoginUserUtil;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.Optional;

/**
 * <p>
 * ExpertAdminDataScopeProviderImpl
 * </p>
 *
 * @author WendyYang
 * @since 10:39 2023/12/11
 */
@Component("EXPERT_ADMIN")
@RequiredArgsConstructor
public class ExpertAdminDataScopeProviderImpl implements DataScopeProvider {

    private final UserInfoHelper userInfoHelper;

    @Override
    public Optional<DataScopeDTO> findDataFieldProperty() {
        UserInfoDetails user = LoginUserUtil.loginUserDetail();
        DataScopeDTO ds = new DataScopeDTO();
        ds.setRole(RoleEnum.EXPERT_ADMIN);
        ds.setUserId(user.getUserId());
        ds.setOrgCode(user.getMhUnitIdStr());
        return Optional.of(ds);
    }

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

}
