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

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sa.ibiz.demo.demo.domain.CodeItem;
import com.sa.ibiz.demo.demo.service.CodeItemService;
import com.sa.ibiz.demo.demo.service.dto.CodeItemSearchFilter;
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/codeitem")
public class CodeItemResource
{
	@Autowired
	private CodeItemService service;


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

	@PostMapping(value="/listdefault")
	public ResponseEntity<List<CodeItem>> listDefault(@Validated @RequestBody CodeItemSearchFilter filter){
		List<CodeItem> searchResult = service.listDefault(filter);
		return ResponseEntity.ok().body(searchResult);
	}
    @PostMapping(value="/searchcurcl")
	public ResponseEntity<Page<CodeItem>> searchCurCLPage(@Validated @RequestBody CodeItemSearchFilter filter){
		Page<CodeItem> searchResult = service.searchCurCL(filter);
		return ResponseEntity.ok().body(searchResult);
	}

	@PostMapping(value="/listcurcl")
	public ResponseEntity<List<CodeItem>> listCurCL(@Validated @RequestBody CodeItemSearchFilter filter){
		List<CodeItem> searchResult = service.listCurCL(filter);
		return ResponseEntity.ok().body(searchResult);
	}
}
