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

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sa.ibiz.demo.demo.domain.DALog;
import com.sa.ibiz.demo.demo.service.DALogService;
import com.sa.ibiz.demo.demo.service.dto.DALogSearchFilter;
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/dalog")
public class DALogResource
{
	@Autowired
	private DALogService service;


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

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