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

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sa.ibiz.demo.demo.domain.UserGroup;
import com.sa.ibiz.demo.demo.service.UserGroupService;
import com.sa.ibiz.demo.demo.service.dto.UserGroupSearchFilter;
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/usergroup")
public class UserGroupResource
{
	@Autowired
	private UserGroupService service;


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

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