package com.zcloud.zcGbsServicer.web;


import com.zcloud.zcGbsServicer.api.ResourceDeviceServiceI;
import com.zcloud.zcGbsServicer.dto.ResourceDeviceAddCmd;
import com.zcloud.zcGbsServicer.dto.ResourceDevicePageQry;
import com.zcloud.zcGbsServicer.dto.ResourceDeviceUpdateCmd;
import com.zcloud.zcGbsServicer.dto.clientobject.ResourceDeviceCO;
import com.alibaba.cola.dto.MultiResponse;
import com.alibaba.cola.dto.PageResponse;
import com.alibaba.cola.dto.Response;
import com.alibaba.cola.dto.SingleResponse;
import com.jjb.saas.framework.auth.model.SSOUser;
import com.jjb.saas.framework.auth.utils.AuthContext;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
/**
* web-adapter
* @Author makejava
* @Date 2026-01-21 17:23:16
*/
@Api(tags = "资源-设备(通用)")
@RequestMapping("/${application.gateway}/resourceDevice")
@RestController
@AllArgsConstructor
public class ResourceDeviceController {
    private final ResourceDeviceServiceI resourceDeviceService;

    @ApiOperation("新增")
    @PostMapping("/save")
    public SingleResponse<ResourceDeviceCO> add(@Validated @RequestBody ResourceDeviceAddCmd cmd) {
        SSOUser ssoUser = AuthContext.getCurrentUser();
        return resourceDeviceService.add(cmd);
    }

    @ApiOperation("分页")
    @PostMapping("/list")
    public PageResponse<ResourceDeviceCO> page(@RequestBody ResourceDevicePageQry qry) {
        return resourceDeviceService.listPage(qry);
    }

    @ApiOperation("所有数据")
    @GetMapping("/listAll")
    public MultiResponse<ResourceDeviceCO> listAll() {
        return MultiResponse.of(new ArrayList<ResourceDeviceCO>());
    }

    @ApiOperation("详情")
    @GetMapping("/{id}")
    public SingleResponse<ResourceDeviceCO> getInfoById(@PathVariable("id") Long id) {
        return SingleResponse.of(new ResourceDeviceCO());
    }

    @ApiOperation("删除")
    @DeleteMapping("/{id}")
    public Response remove(@PathVariable("id") Long id) {
        resourceDeviceService.remove(id);
        return SingleResponse.buildSuccess();
    }

    @ApiOperation("删除多个")
    @DeleteMapping("/ids")
        public Response removeBatch(@RequestParam Long[] ids) {
        resourceDeviceService.removeBatch(ids);
        return SingleResponse.buildSuccess();
    }

    @ApiOperation("修改")
    @PutMapping("/edit")
    public SingleResponse edit(@Validated @RequestBody ResourceDeviceUpdateCmd resourceDeviceUpdateCmd) {
        resourceDeviceService.edit(resourceDeviceUpdateCmd);
        return SingleResponse.buildSuccess();
    }
}

