package com.auth.service.base.controller;

import com.auth.common.model.common.result.PageResult;
import com.auth.common.model.common.result.Result;
import com.auth.common.model.common.result.ResultCodeEnum;
import com.auth.model.base.dto.OperationLogDto;
import com.auth.model.base.vo.OperationLogVo;
import com.auth.dao.base.entity.OperationLogEntity;
import com.auth.service.base.service.OperationLogService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 系统操作日志 前端控制器
 * </p>
 *
 * @author AuthoritySystem
 * @since 2025-07-17 23:06:38
 */
@Tag(name = "系统操作日志", description = "系统操作日志相关接口")
@RestController
@RequestMapping("/api/v1/base/operation-log")
@RequiredArgsConstructor
public class OperationLogController {

    private final OperationLogService operationLogService;

    @Operation(summary = "分页查询系统操作日志", description = "分页查询系统操作日志")
    @GetMapping("{page}/{limit}")
    public Result<PageResult<OperationLogVo>> getOperationLogPage(
            @Parameter(name = "page", description = "当前页", required = true)
            @PathVariable("page") Integer page,
            @Parameter(name = "limit", description = "每页记录数", required = true)
            @PathVariable("limit") Integer limit,
            OperationLogDto dto) {
        Page<OperationLogEntity> pageParams = new Page<>(page, limit);
        PageResult<OperationLogVo> pageResult = operationLogService.getOperationLogPage(pageParams, dto);
        return Result.success(pageResult);
    }

    @Operation(summary = "根据id查询系统操作日志详情", description = "根据id查询系统操作日志详情")
    @GetMapping("{id}")
    public Result<OperationLogVo> getOperationLogById(@PathVariable("id") Long id) {
        OperationLogVo operationLogVo = operationLogService.getOperationLogById(id);

        return Result.success(operationLogVo);
    }

    @Operation(summary = "添加系统操作日志", description = "添加系统操作日志")
    @PostMapping()
    public Result<String> addOperationLog(@Valid @RequestBody OperationLogDto dto) {
        operationLogService.addOperationLog(dto);
        return Result.success(ResultCodeEnum.ADD_SUCCESS);
    }

    @Operation(summary = "更新系统操作日志", description = "更新系统操作日志")
    @PutMapping()
    public Result<String> updateOperationLog(@Valid @RequestBody OperationLogDto dto) {
        operationLogService.updateOperationLog(dto);
        return Result.success(ResultCodeEnum.UPDATE_SUCCESS);
    }

    @Operation(summary = "删除系统操作日志", description = "删除系统操作日志")
    @DeleteMapping()
    public Result<String> deleteOperationLog(@RequestBody List<Long> ids) {
        operationLogService.deleteOperationLog(ids);
        return Result.success(ResultCodeEnum.DELETE_SUCCESS);
    }
}