package com.zhongshu.card.server.core.controller.user;

import com.github.microservice.auth.security.annotations.ResourceAuth;
import com.github.microservice.auth.security.type.AuthType;
import com.zhongshu.card.client.model.operLogs.OperationLogsAddParam;
import com.zhongshu.card.client.model.operLogs.OperationLogsModel;
import com.zhongshu.card.client.model.operLogs.OperationLogsSearchParam;
import com.github.microservice.net.ResultContent;
import com.zhongshu.card.client.model.org.OrgUserDetailParam;
import com.zhongshu.card.client.model.org.OrganizationUserModel;
import com.zhongshu.card.server.core.service.user.OperationLogsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.web.PageableDefault;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

/**
 * 日志管理 服务
 *
 * @author TRX
 * @date 2024/3/21
 */
@RequestMapping("/operationLogs")
@RestController
@Validated
@Tag(name = "日志管理")
public class OperationLogsController {

    @Autowired
    OperationLogsService operationLogsService;

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "设备列表-分页查询")
    @RequestMapping(value = {"page"}, method = {RequestMethod.POST})
    public ResultContent<Page<OperationLogsModel>> page(@Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable,
            @Parameter(required = false) OperationLogsSearchParam param) {
        return operationLogsService.pageLogs(pageable, param);
    }

    @Operation(summary = "添加日志", description = "添加日志")
    @RequestMapping(value = "manager/addLog", method = {RequestMethod.POST})
    public ResultContent<OrganizationUserModel> addLog(@RequestBody OperationLogsAddParam param) {
        operationLogsService.addLog(param);
        return ResultContent.buildSuccess();
    }

}
