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

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.deviceProduct.DeviceProductProvideServeModel;
import com.zhongshu.card.client.model.devices.deviceProduct.DeviceProductProvideServeParam;
import com.zhongshu.card.client.model.devices.deviceProduct.DeviceProductProvideServeSearch;
import com.zhongshu.card.server.core.service.devices.deviceProduct.DeviceProductProvideServeService;
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("/deviceProductProvideServe")
@Tag(name = "产品管理-产品服务")
public class DeviceProductProvideServeController {

    @Autowired
    private DeviceProductProvideServeService deviceProductProvideServeService;

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "保存数据", description = "保存数据")
    @RequestMapping(value = "saveInfo", method = {RequestMethod.POST})
    public ResultContent saveInfo(@RequestBody DeviceProductProvideServeParam param) {
        return this.deviceProductProvideServeService.saveInfo(param);
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "删除服务", description = "删除服务")
    @RequestMapping(value = "deleteInfo", method = {RequestMethod.POST})
    public ResultContent deleteInfo(@RequestBody IDParam param) {
        return this.deviceProductProvideServeService.deleteInfo(param.getId());
    }

    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "服务数据列表-分页查询", description = "服务数据列表-分页查询")
    @RequestMapping(value = {"page"}, method = {RequestMethod.POST})
    public ResultContent<Page<DeviceProductProvideServeModel>> page(
            @Parameter(hidden = true) @PageableDefault(page = 0, size = 10) Pageable pageable,
            @Parameter(required = false) DeviceProductProvideServeSearch param) {
        Assert.hasText(param.getProjectOid(), "projectOid不能为空");
        Assert.hasText(param.getDeviceProductId(), "deviceProductId不能为空");
        return deviceProductProvideServeService.page(param, pageable);
    }
    
    @ResourceAuth(value = "user", type = AuthType.User)
    @Operation(summary = "服务详情", description = "服务详情")
    @RequestMapping(value = "getDetailInfo", method = {RequestMethod.POST})
    public ResultContent getDetailInfo(@RequestBody IDParam param) {
        return this.deviceProductProvideServeService.getDetailInfo(param.getId());
    }

}
