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

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sa.ibiz.demo.demo.domain.WXEntApp;
import com.sa.ibiz.demo.demo.service.WXEntAppService;
import com.sa.ibiz.demo.demo.service.dto.WXEntAppSearchFilter;
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/wxentapp")
public class WXEntAppResource
{
	@Autowired
	private WXEntAppService service;


	@GetMapping(value = "/{id}")
	public ResponseEntity<WXEntApp> get(@Validated @PathVariable String id){
		WXEntApp data=new WXEntApp();
		data.setWxentappid(id);;
		data=service.get(data);
		if(data==null)
			throw new BadRequestAlertException("微信企业应用[get]操作发生错误","WXEntApp",id.toString());
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/update")
	public ResponseEntity<WXEntApp> update(@Validated @RequestBody WXEntApp data){
		boolean bRt=service.update(data);
		if(!bRt)
			throw new BadRequestAlertException("微信企业应用[update]操作发生错误","WXEntApp",data.getWxentappid().toString());
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/create")
	public ResponseEntity<WXEntApp> create(@Validated @RequestBody WXEntApp data){
		boolean bRt=service.create(data);
		if(!bRt)
			throw new BadRequestAlertException("微信企业应用[create]操作发生错误","WXEntApp",data.getWxentappid().toString());
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/checkKey")
	public ResponseEntity<WXEntApp> checkKey(@Validated @RequestBody WXEntApp data){
		boolean bRt=service.checkKey(data);
		if(!bRt)
			throw new BadRequestAlertException("微信企业应用[checkKey]操作发生错误","WXEntApp",data.getWxentappid().toString());
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/remove")
	public ResponseEntity<WXEntApp> remove(@Validated @RequestBody WXEntApp data){
		boolean bRt=service.remove(data);
		if(!bRt)
			throw new BadRequestAlertException("微信企业应用[remove]操作发生错误","WXEntApp",data.getWxentappid().toString());
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/getDraft")
	public ResponseEntity<WXEntApp> getDraft(@Validated @RequestBody WXEntApp data){
		boolean bRt=service.getDraft(data);
		if(!bRt)
			throw new BadRequestAlertException("微信企业应用[getDraft]操作发生错误","WXEntApp","");
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/pubMenu")
	public ResponseEntity<WXEntApp> pubMenu(@Validated @RequestBody WXEntApp data){
		service.pubMenu(data);
		return ResponseEntity.ok().body(data);
	}
    @PostMapping(value="/searchdefault")
	public ResponseEntity<Page<WXEntApp>> searchDefaultPage(@Validated @RequestBody WXEntAppSearchFilter filter){
		Page<WXEntApp> searchResult = service.searchDefault(filter);
		return ResponseEntity.ok().body(searchResult);
	}

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