package com.sa.ibiz.demo.demo.rest;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sa.ibiz.demo.demo.domain.UserDictCat;
import com.sa.ibiz.demo.demo.service.UserDictCatService;
import com.sa.ibiz.demo.demo.service.dto.UserDictCatSearchFilter;
import com.sa.ibiz.demo.ibizutil.errors.BadRequestAlertException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import java.math.BigInteger;
import java.util.List;

@RestController
@RequestMapping("/demo/userdictcat")
public class UserDictCatResource
{
	@Autowired
	private UserDictCatService service;


	@PostMapping(value = "/update")
	public ResponseEntity<UserDictCat> update(@Validated @RequestBody UserDictCat data){
		boolean bRt=service.update(data);
		if(!bRt)
			throw new BadRequestAlertException("用户词条类别[update]操作发生错误","UserDictCat",data.getUserdictcatid().toString());
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/checkKey")
	public ResponseEntity<UserDictCat> checkKey(@Validated @RequestBody UserDictCat data){
		boolean bRt=service.checkKey(data);
		if(!bRt)
			throw new BadRequestAlertException("用户词条类别[checkKey]操作发生错误","UserDictCat",data.getUserdictcatid().toString());
		return ResponseEntity.ok().body(data);
	}
	@GetMapping(value = "/{id}")
	public ResponseEntity<UserDictCat> get(@Validated @PathVariable String id){
		UserDictCat data=new UserDictCat();
		data.setUserdictcatid(id);;
		data=service.get(data);
		if(data==null)
			throw new BadRequestAlertException("用户词条类别[get]操作发生错误","UserDictCat",id.toString());
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/getDraft")
	public ResponseEntity<UserDictCat> getDraft(@Validated @RequestBody UserDictCat data){
		boolean bRt=service.getDraft(data);
		if(!bRt)
			throw new BadRequestAlertException("用户词条类别[getDraft]操作发生错误","UserDictCat","");
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/remove")
	public ResponseEntity<UserDictCat> remove(@Validated @RequestBody UserDictCat data){
		boolean bRt=service.remove(data);
		if(!bRt)
			throw new BadRequestAlertException("用户词条类别[remove]操作发生错误","UserDictCat",data.getUserdictcatid().toString());
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/create")
	public ResponseEntity<UserDictCat> create(@Validated @RequestBody UserDictCat data){
		boolean bRt=service.create(data);
		if(!bRt)
			throw new BadRequestAlertException("用户词条类别[create]操作发生错误","UserDictCat",data.getUserdictcatid().toString());
		return ResponseEntity.ok().body(data);
	}
    @PostMapping(value="/searchdefault")
	public ResponseEntity<Page<UserDictCat>> searchDefaultPage(@Validated @RequestBody UserDictCatSearchFilter filter){
		Page<UserDictCat> searchResult = service.searchDefault(filter);
		return ResponseEntity.ok().body(searchResult);
	}

	@PostMapping(value="/listdefault")
	public ResponseEntity<List<UserDictCat>> listDefault(@Validated @RequestBody UserDictCatSearchFilter filter){
		List<UserDictCat> searchResult = service.listDefault(filter);
		return ResponseEntity.ok().body(searchResult);
	}
}
