package com.yimeng.okr.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yimeng.okr.dto.ApiResult;
import com.yimeng.okr.entity.OperationLog;
import com.yimeng.okr.enums.UserRole;
import com.yimeng.okr.exception.BusinessException;
import com.yimeng.okr.security.SecurityUtils;
import com.yimeng.okr.service.SystemService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/system")
@RequiredArgsConstructor
public class SystemController {

    private final SystemService systemService;

    @GetMapping("/logs")
    public ApiResult<Page<OperationLog>> getLogs(
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "20") int size,
            @RequestParam(required = false) String action,
            @RequestParam(required = false) String entityType) {
        if (!SecurityUtils.hasRole(UserRole.HR_ADMIN)) {
            throw new BusinessException(403, "无权限，需要HR管理员或以上权限");
        }
        return ApiResult.success(systemService.getLogs(page, size, action, entityType));
    }
}
