package com.usky.iot.controller.web;


import com.usky.common.core.bean.ApiResult;
import com.usky.common.core.bean.CommonPage;
import com.usky.iot.domain.DmpDeviceType;
import com.usky.iot.service.DmpDeviceTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 * 设备信息类型 前端控制器
 * </p>
 *
 * @author ya
 * @since 2023-06-06
 */
@RestController
@RequestMapping("/dmpDeviceType")
public class DmpDeviceTypeController {
    @Autowired
    private DmpDeviceTypeService dmpDeviceTypeService;

    /**
     * 新增
     * @param dmpDeviceType
     * @return
     */
    @PostMapping("add")
    public ApiResult<Void> add(@RequestBody DmpDeviceType dmpDeviceType){
        dmpDeviceTypeService.add(dmpDeviceType);
        return ApiResult.success();
    }

    /**
     * 修改
     * @param dmpDeviceType
     * @return
     */
    @PutMapping("edit")
    public ApiResult<Void> edit(@RequestBody DmpDeviceType dmpDeviceType){
        dmpDeviceTypeService.edit(dmpDeviceType);
        return ApiResult.success();
    }

    /**
     * 删除
     * @param id
     * @return
     */
    @DeleteMapping("remove")
    public ApiResult<Void> remove(@RequestParam("id") Integer id){
        dmpDeviceTypeService.remove(id);
        return ApiResult.success();
    }

    /**
     *  列表查询
     *
     * @param typeCode 类型编号
     * @param typeName 类型名称
     * @param pageNum 当前页
     * @param pageSize 每页条数
     * @return
     */
    @GetMapping("getDeviceTypeList")
    public ApiResult<CommonPage<DmpDeviceType>> getDeviceTypeList(@RequestParam(value = "typeCode",required = false) String typeCode,
                                                                  @RequestParam(value = "typeName",required = false) String typeName,
                                                                  @RequestParam(value = "typeDomain",required = false) Integer typeDomain,
                                                                  @RequestParam(value = "pageNum", required = false, defaultValue = "1") Integer pageNum,
                                                                  @RequestParam(value = "pageSize", required = false, defaultValue = "10") Integer pageSize){
        return ApiResult.success(dmpDeviceTypeService.getDeviceTypeList(typeCode,typeName,typeDomain,pageNum,pageSize));
    }

    /**
     * 租户设备类型列表
     * @return
     */
    @GetMapping("tenantIdDeviceTypeList")
    public ApiResult<List<DmpDeviceType>> tenantIdDeviceTypeList(){
        return ApiResult.success(dmpDeviceTypeService.tenantIdDeviceTypeList());
    }

}

