package com.skr.mdm.api.app.controller;

import com.skr.mdm.api.app.service.AppTypeService;
import com.skr.mdm.bean.qo.app.AppTypeQO;
import com.skr.mdm.bean.vo.appstore.AppTypeVO;
import com.skr.mdm.dto.LoginAdminDTO;
import com.skr.mdm.result.ResponseResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.Authentication;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import springfox.documentation.annotations.ApiIgnore;

import javax.validation.Valid;
import javax.validation.constraints.NotEmpty;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * @author nfq
 * @date 2022-11-21 14:13
 */
@Validated
@RestController
@RequestMapping("appType")
@Api(tags = "应用类型")
public class AppTypeController {

	@Autowired
	private AppTypeService appTypeService;

	@PostMapping("list")
	@ApiOperation(value = "分页列表", response = AppTypeVO.class)
	public ResponseResult listPage(@NotNull(message = "pageNum不能为空") @RequestParam Integer pageNum,
								   @NotNull(message = "pageSize不能为空") @RequestParam Integer pageSize,
								   @ApiIgnore Authentication authentication) {
		LoginAdminDTO loginAdminDTO = (LoginAdminDTO) authentication.getPrincipal();
		return appTypeService.listPage(pageNum, pageSize, loginAdminDTO);
	}

	@PostMapping("list/all")
	@ApiOperation(value = "下拉框列表", response = AppTypeVO.class)
	public List<AppTypeVO> listAll(@ApiIgnore Authentication authentication) {
		LoginAdminDTO loginAdminDTO = (LoginAdminDTO) authentication.getPrincipal();
		return appTypeService.listAll(loginAdminDTO);
	}

	@PostMapping("add")
	@ApiOperation("添加")
	public ResponseResult add(@RequestBody @Valid AppTypeQO appTypeQO, @ApiIgnore Authentication authentication) {
		LoginAdminDTO loginAdminDTO = (LoginAdminDTO) authentication.getPrincipal();
		return appTypeService.add(appTypeQO, loginAdminDTO);
	}

	@PostMapping("update")
	@ApiOperation("编辑")
	public ResponseResult update(@RequestBody @Valid AppTypeQO appTypeQO, @ApiIgnore Authentication authentication) {
		LoginAdminDTO loginAdminDTO = (LoginAdminDTO) authentication.getPrincipal();
		return appTypeService.update(appTypeQO, loginAdminDTO);
	}

	@PostMapping("delete")
	@ApiOperation("删除")
	public ResponseResult delete(@RequestParam @NotEmpty(message = "应用类型ID不能为空") List<Integer> appTypeIdList, @ApiIgnore Authentication authentication) {
		LoginAdminDTO loginAdminDTO = (LoginAdminDTO) authentication.getPrincipal();
		return appTypeService.delete(appTypeIdList, loginAdminDTO);
	}

}