package com.usky.rule.controller.web;

import com.usky.common.core.bean.ApiResult;
import com.usky.common.core.bean.CommonPage;
import com.usky.common.log.annotation.Log;
import com.usky.common.log.enums.BusinessType;
import com.usky.common.security.utils.SecurityUtils;
import com.usky.rule.domain.RuleEngineLog;
import com.usky.rule.service.RuleEngineLogService;
import com.usky.rule.vo.RuleEngineContent;
import com.usky.rule.vo.RuleEngineLogPageRequest;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

/**
 * 数据规则日志界面 API（表 rule_engine_log）
 */
@Api(tags = "数据规则日志")
@RestController
@RequestMapping("/ruleEngineLog")
public class RuleEngineLogController {
    private final RuleEngineLogService ruleEngineLogService;

    public RuleEngineLogController(RuleEngineLogService ruleEngineLogService) {
        this.ruleEngineLogService = ruleEngineLogService;
    }

    @ApiOperation("规则执行日志分页")
    @PostMapping("/page")
    public ApiResult<CommonPage<RuleEngineLog>> page(@RequestBody RuleEngineLogPageRequest request) {
        if (request.getTenantId() == null) {
            try {
                request.setTenantId(SecurityUtils.getTenantId());
            } catch (Exception ignored) {
            }
        }
        return ApiResult.success(ruleEngineLogService.pageList(request));
    }

    @ApiOperation("规则执行日志详情")
    @GetMapping("/{id}")
    public ApiResult<RuleEngineContent> detail(@PathVariable("id") Long id) {
        return ApiResult.success(ruleEngineLogService.getById(id));
    }

    @ApiOperation("删除规则执行日志")
    @DeleteMapping("/{id}")
    public ApiResult<Void> remove(@PathVariable("id") Long id) {
        ruleEngineLogService.remove(id);
        return ApiResult.success();
    }
}
