package com.yimeng.okr.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.yimeng.okr.dto.ApiResult;
import com.yimeng.okr.entity.OperationLog;
import com.yimeng.okr.mapper.OperationLogMapper;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

@Service
@RequiredArgsConstructor
public class SystemService {

    private final OperationLogMapper logMapper;

    public Page<OperationLog> getLogs(int page, int size, String action, String entityType) {
        Page<OperationLog> p = new Page<>(page, size);
        LambdaQueryWrapper<OperationLog> wrapper = new LambdaQueryWrapper<>();
        if (action != null && !action.isEmpty()) {
            wrapper.eq(OperationLog::getAction, action);
        }
        if (entityType != null && !entityType.isEmpty()) {
            wrapper.eq(OperationLog::getEntityType, entityType);
        }
        wrapper.orderByDesc(OperationLog::getCreatedAt);
        return logMapper.selectPage(p, wrapper);
    }
}
