/*
* Copyright (c) 京北方信息技术股份有限公司 Corporation 2022 . All rights reserved.
*
*/
package net.northking.cctp.device.api.brand;

import cn.gjing.tools.auth.annotation.RequiredPermissions;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import net.northking.cctp.common.http.ResultWrapper;

import net.northking.cctp.device.api.brand.service.CdMobileBrandApiService;
import net.northking.cctp.device.dto.brand.CdMobileBrandAddDto;
import net.northking.cctp.device.dto.brand.CdMobileBrandDetailDto;
import net.northking.cctp.device.dto.brand.CdMobileBrandUpdateDto;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

/**
 * 移动设备品牌表 => Restful 类型 HTTP/HTTPS 接口
 *
 * @author maven-cctp-plugin
 * @since 1.0
 */
@Api(tags = "移动设备品牌表")
@RequestMapping("/v1/brands")
@RestController
public class CdMobileBrandRestfulCtrl
{
  /**
   * 日志
   */
  private final static Logger logger = LoggerFactory.getLogger(CdMobileBrandRestfulCtrl.class);

  @Autowired
  private CdMobileBrandApiService apiService;

  /**
   * Restful接口-post： 新增移动设备品牌表
   *
   * @param
   * @return 数据库主键
   */
  @ApiOperation(value = "新增：移动设备品牌表")
  @PostMapping()
  public ResultWrapper<String> add(@RequestBody CdMobileBrandAddDto inputDto)
  {
    ResultWrapper<String> wrapper = new ResultWrapper<>();
    String uuid = apiService.add(inputDto);
    return wrapper.success(uuid);
  }

  /**
   * Restful接口-put： 更新移动设备品牌表
   *
   * @param
   * @return 修改的记录数量
   */
  @ApiOperation(value = "更新：移动设备品牌表")
  @PutMapping()
  @RequiredPermissions(value = {"ui-updateBrands","ui-updateBrands2"})
  public ResultWrapper<Integer> update(@RequestBody CdMobileBrandUpdateDto inputDto) throws IllegalAccessException
  {
    ResultWrapper<Integer> wrapper = new ResultWrapper<>();
    Integer count = apiService.updateByPK(inputDto);
    return wrapper.success(count);
  }

  /**
   * Restful接口-get： 获取移动设备品牌表
   *
   * @param uuid       数据库主键
   * @return 接口数据传输对象
   */
  @ApiOperation(value = "获取：移动设备品牌表")
  @GetMapping(
      value = "/{uuid}",
      produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public ResultWrapper<CdMobileBrandDetailDto> findByPK(
      @PathVariable("uuid") String uuid)
  {
    ResultWrapper<CdMobileBrandDetailDto> wrapper = new ResultWrapper<>();
    CdMobileBrandDetailDto user = apiService.findByPK(uuid);
    return wrapper.success(user);
  }

  /**
   * Restful接口-delete： 删除移动设备品牌表
   *
   * @param uuid       数据库主键
   * @return 删除的记录数量
   */
  @ApiOperation(value = "删除：移动设备品牌表")
  @DeleteMapping(
      value = "/{uuid}",
      produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
  public ResultWrapper<Integer> deleteByPK(
      @PathVariable("uuid") String uuid)
  {
    ResultWrapper<Integer> wrapper = new ResultWrapper<>();
    Integer count = apiService.deleteByPK(uuid);
    return wrapper.success(count);
  }
}
