package com.yaoai.admin.auth;

import com.yaoai.domain.entity.AdminUser;
import com.yaoai.domain.mapper.AdminUserMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.List;

@Component
@RequiredArgsConstructor
public class AdminPermissionInterface implements cn.dev33.satoken.stp.StpInterface {

    private final AdminUserMapper adminUserMapper;

    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        return Collections.emptyList();
    }

    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        if (!"admin".equals(loginType)) {
            return Collections.emptyList();
        }
        AdminUser user = adminUserMapper.selectById(Long.parseLong(loginId.toString()));
        if (user == null || user.getRole() == null) {
            return Collections.emptyList();
        }
        return List.of(user.getRole());
    }
}
