package com.yuchen.saas.park.service.controller.door.util;

import org.nest.springwrap.core.secure.ContextUser;
import org.nest.springwrap.core.secure.utils.AuthUtil;

import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.Positive;
import java.util.Optional;
import java.util.Set;

public abstract class OrganizationIdExtractor {
    @Positive
    public static long extract() {
        return Optional.ofNullable(AuthUtil.getUser())
          .map(ContextUser::getDeptId)
          .map(Long::parseLong)
          .filter(o -> o > 0)
          .orElseThrow();
    }

    @NotEmpty
    public static Set<@Positive Long> extractSet() {
        return Set.of(extract());
    }
}
