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

import com.github.microservice.auth.security.annotations.ResourceAuth;
import com.github.microservice.auth.security.type.AuthType;
import com.github.microservice.net.ResultContent;
import com.zhongshu.card.client.model.base.IDParam;
import com.zhongshu.card.client.model.devices.DeviceUseRecordModel;
import com.zhongshu.card.client.model.devices.DeviceUseRecordSearch;
import com.zhongshu.card.server.core.service.devices.DeviceUseRecordService;
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.util.Assert;
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/6/5
 */
@RestController
@RequestMapping("/deviceUse")
@Tag(name = "平台-设备使用日志")
public class DeviceUseRecordController {

    @Autowired
    private DeviceUseRecordService deviceUseRecordService;

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "设备使用详情", description = "设备使用详情")
    @RequestMapping(value = "getDetail", method = {RequestMethod.POST})
    public ResultContent getDetail(@RequestBody IDParam param) {
        return this.deviceUseRecordService.getDetail(param.getId());
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "删除设备使用记录", description = "删除设备使用记录")
    @RequestMapping(value = "deleteById", method = {RequestMethod.POST})
    public ResultContent deleteById(@RequestBody IDParam param) {
        return this.deviceUseRecordService.deleteById(param.getId());
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "设备使用记录列表-分页查询", description = "设备使用记录列表-分页查询")
    @RequestMapping(value = {"page"}, method = {RequestMethod.POST})
    public ResultContent<Page<DeviceUseRecordModel>> page(@Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable, @Parameter(required = false) DeviceUseRecordSearch param) {
        Assert.hasText(param.getProjectOid(), "projectOid不能为空");
        return deviceUseRecordService.page(param, pageable);
    }

}
