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

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sa.ibiz.demo.demo.domain.UserObject;
import com.sa.ibiz.demo.demo.service.UserObjectService;
import com.sa.ibiz.demo.demo.service.dto.UserObjectSearchFilter;
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/userobject")
public class UserObjectResource
{
	@Autowired
	private UserObjectService service;


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

	@PostMapping(value="/listdefault")
	public ResponseEntity<List<UserObject>> listDefault(@Validated @RequestBody UserObjectSearchFilter filter){
		List<UserObject> searchResult = service.listDefault(filter);
		return ResponseEntity.ok().body(searchResult);
	}
    @PostMapping(value="/searchindexder")
	public ResponseEntity<Page<UserObject>> searchIndexDERPage(@Validated @RequestBody UserObjectSearchFilter filter){
		Page<UserObject> searchResult = service.searchIndexDER(filter);
		return ResponseEntity.ok().body(searchResult);
	}

	@PostMapping(value="/listindexder")
	public ResponseEntity<List<UserObject>> listIndexDER(@Validated @RequestBody UserObjectSearchFilter filter){
		List<UserObject> searchResult = service.listIndexDER(filter);
		return ResponseEntity.ok().body(searchResult);
	}
}
