package com.njcn.rdms.module.system.api.permission;

import com.njcn.rdms.framework.common.pojo.CommonResult;
import com.njcn.rdms.framework.test.core.ut.BaseMockitoUnitTest;
import com.njcn.rdms.module.system.dal.dataobject.permission.RoleDO;
import com.njcn.rdms.module.system.enums.permission.RoleCodeEnum;
import com.njcn.rdms.module.system.service.permission.PermissionService;
import com.njcn.rdms.module.system.service.permission.RoleService;
import org.junit.jupiter.api.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;

import java.util.List;
import java.util.Set;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.Mockito.when;

class PermissionApiImplTest extends BaseMockitoUnitTest {

    @Mock
    private PermissionService permissionService;

    @Mock
    private RoleService roleService;

    @InjectMocks
    private PermissionApiImpl permissionApi;

    @Test
    void isSuperAdmin_returnsTrue_whenUserHasSuperAdminRole() {
        Long userId = 1L;
        Set<Long> roleIds = Set.of(100L);
        when(permissionService.getUserRoleIdListByUserId(userId)).thenReturn(roleIds);
        when(roleService.hasAnySuperAdmin(roleIds)).thenReturn(true);

        CommonResult<Boolean> result = permissionApi.isSuperAdmin(userId);

        assertTrue(result.getCheckedData());
    }

    @Test
    void isSuperAdmin_returnsFalse_otherwise() {
        Long userId = 2L;
        Set<Long> roleIds = Set.of(200L);
        when(permissionService.getUserRoleIdListByUserId(userId)).thenReturn(roleIds);
        when(roleService.hasAnySuperAdmin(roleIds)).thenReturn(false);

        CommonResult<Boolean> result = permissionApi.isSuperAdmin(userId);

        assertFalse(result.getCheckedData());
    }

}
