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

    private final UserInfoHelper userInfoHelper;

    @Override
    public Optional<DataScopeDTO> findDataFieldProperty() {
        UserFullInfoDTO userFullInfo = userInfoHelper.getUserFullInfo(LoginUserUtil.getUserId());
        DataScopeDTO ds = new DataScopeDTO();
        ds.setOrgCode(String.valueOf(userFullInfo.getMhUnitId()));
        ds.setUserId(userFullInfo.getUserId());
        ds.setRole(RoleEnum.COMPANY_MANAGER);
        return Optional.of(ds);
    }

    @Override
    public Optional<DataScopeDTO> findDataFieldProperty(Long userId) {
        UserFullInfoDTO userFullInfo = userInfoHelper.getUserFullInfo(userId);
        DataScopeDTO ds = new DataScopeDTO();
        ds.setOrgCode(String.valueOf(userFullInfo.getMhUnitId()));
        ds.setUserId(userFullInfo.getUserId());
        ds.setRole(RoleEnum.COMPANY_MANAGER);
        return Optional.of(ds);
    }
}
