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

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sa.ibiz.demo.demo.domain.UserRoleDatas;
import com.sa.ibiz.demo.demo.service.UserRoleDatasService;
import com.sa.ibiz.demo.demo.service.dto.UserRoleDatasSearchFilter;
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/userroledatas")
public class UserRoleDatasResource
{
	@Autowired
	private UserRoleDatasService service;


	@PostMapping(value = "/getDraft")
	public ResponseEntity<UserRoleDatas> getDraft(@Validated @RequestBody UserRoleDatas data){
		boolean bRt=service.getDraft(data);
		if(!bRt)
			throw new BadRequestAlertException("用户角色数据能力[getDraft]操作发生错误","UserRoleDatas","");
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/checkKey")
	public ResponseEntity<UserRoleDatas> checkKey(@Validated @RequestBody UserRoleDatas data){
		boolean bRt=service.checkKey(data);
		if(!bRt)
			throw new BadRequestAlertException("用户角色数据能力[checkKey]操作发生错误","UserRoleDatas",data.getUserroledatasid().toString());
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/update")
	public ResponseEntity<UserRoleDatas> update(@Validated @RequestBody UserRoleDatas data){
		boolean bRt=service.update(data);
		if(!bRt)
			throw new BadRequestAlertException("用户角色数据能力[update]操作发生错误","UserRoleDatas",data.getUserroledatasid().toString());
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/remove")
	public ResponseEntity<UserRoleDatas> remove(@Validated @RequestBody UserRoleDatas data){
		boolean bRt=service.remove(data);
		if(!bRt)
			throw new BadRequestAlertException("用户角色数据能力[remove]操作发生错误","UserRoleDatas",data.getUserroledatasid().toString());
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/create")
	public ResponseEntity<UserRoleDatas> create(@Validated @RequestBody UserRoleDatas data){
		boolean bRt=service.create(data);
		if(!bRt)
			throw new BadRequestAlertException("用户角色数据能力[create]操作发生错误","UserRoleDatas",data.getUserroledatasid().toString());
		return ResponseEntity.ok().body(data);
	}
	@GetMapping(value = "/{id}")
	public ResponseEntity<UserRoleDatas> get(@Validated @PathVariable String id){
		UserRoleDatas data=new UserRoleDatas();
		data.setUserroledatasid(id);;
		data=service.get(data);
		if(data==null)
			throw new BadRequestAlertException("用户角色数据能力[get]操作发生错误","UserRoleDatas",id.toString());
		return ResponseEntity.ok().body(data);
	}
    @PostMapping(value="/searchdefault")
	public ResponseEntity<Page<UserRoleDatas>> searchDefaultPage(@Validated @RequestBody UserRoleDatasSearchFilter filter){
		Page<UserRoleDatas> searchResult = service.searchDefault(filter);
		return ResponseEntity.ok().body(searchResult);
	}

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