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

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sa.ibiz.demo.demo.domain.MsgTemplate;
import com.sa.ibiz.demo.demo.service.MsgTemplateService;
import com.sa.ibiz.demo.demo.service.dto.MsgTemplateSearchFilter;
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/msgtemplate")
public class MsgTemplateResource
{
	@Autowired
	private MsgTemplateService service;


	@PostMapping(value = "/remove")
	public ResponseEntity<MsgTemplate> remove(@Validated @RequestBody MsgTemplate data){
		boolean bRt=service.remove(data);
		if(!bRt)
			throw new BadRequestAlertException("消息模板[remove]操作发生错误","MsgTemplate",data.getMsgtemplateid().toString());
		return ResponseEntity.ok().body(data);
	}
	@GetMapping(value = "/{id}")
	public ResponseEntity<MsgTemplate> get(@Validated @PathVariable String id){
		MsgTemplate data=new MsgTemplate();
		data.setMsgtemplateid(id);;
		data=service.get(data);
		if(data==null)
			throw new BadRequestAlertException("消息模板[get]操作发生错误","MsgTemplate",id.toString());
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/checkKey")
	public ResponseEntity<MsgTemplate> checkKey(@Validated @RequestBody MsgTemplate data){
		boolean bRt=service.checkKey(data);
		if(!bRt)
			throw new BadRequestAlertException("消息模板[checkKey]操作发生错误","MsgTemplate",data.getMsgtemplateid().toString());
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/update")
	public ResponseEntity<MsgTemplate> update(@Validated @RequestBody MsgTemplate data){
		boolean bRt=service.update(data);
		if(!bRt)
			throw new BadRequestAlertException("消息模板[update]操作发生错误","MsgTemplate",data.getMsgtemplateid().toString());
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/create")
	public ResponseEntity<MsgTemplate> create(@Validated @RequestBody MsgTemplate data){
		boolean bRt=service.create(data);
		if(!bRt)
			throw new BadRequestAlertException("消息模板[create]操作发生错误","MsgTemplate",data.getMsgtemplateid().toString());
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/getDraft")
	public ResponseEntity<MsgTemplate> getDraft(@Validated @RequestBody MsgTemplate data){
		boolean bRt=service.getDraft(data);
		if(!bRt)
			throw new BadRequestAlertException("消息模板[getDraft]操作发生错误","MsgTemplate","");
		return ResponseEntity.ok().body(data);
	}
    @PostMapping(value="/searchdefault")
	public ResponseEntity<Page<MsgTemplate>> searchDefaultPage(@Validated @RequestBody MsgTemplateSearchFilter filter){
		Page<MsgTemplate> searchResult = service.searchDefault(filter);
		return ResponseEntity.ok().body(searchResult);
	}

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