package cn.skcks.matrix.v2.services.casbin.init;

import cn.skcks.matrix.v2.model.route.dto.RouteInfo;
import cn.skcks.matrix.v2.services.casbin.CasbinRegister;
import cn.skcks.matrix.v2.services.role.RoleService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.casbin.jcasbin.main.Enforcer;
import org.springframework.stereotype.Component;

import java.util.List;

import static cn.skcks.matrix.v2.services.casbin.CasbinService.*;

@Slf4j
@Component
@RequiredArgsConstructor
public class SuperRoleRegister implements CasbinRegister {

    @Override
    public void register(Enforcer enforcer, List<RouteInfo> routes, RoleService roleService) {
        log.info("[casbin] 初始化 {} 权限", SUPER_PERMISSION_NAME);
        roleService.initRole(SUPER_PERMISSION, SUPER_PERMISSION_NAME, true);
        CasbinRegister.addPolicies(enforcer, SUPER_ROLE, DEFAULT_SYSTEM, routes);
    }
}
