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

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sa.ibiz.demo.demo.domain.WXAccount;
import com.sa.ibiz.demo.demo.service.WXAccountService;
import com.sa.ibiz.demo.demo.service.dto.WXAccountSearchFilter;
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/wxaccount")
public class WXAccountResource
{
	@Autowired
	private WXAccountService service;


	@PostMapping(value = "/syncOrgSector")
	public ResponseEntity<WXAccount> syncOrgSector(@Validated @RequestBody WXAccount data){
		service.syncOrgSector(data);
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/pubMenu")
	public ResponseEntity<WXAccount> pubMenu(@Validated @RequestBody WXAccount data){
		service.pubMenu(data);
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/remove")
	public ResponseEntity<WXAccount> remove(@Validated @RequestBody WXAccount data){
		boolean bRt=service.remove(data);
		if(!bRt)
			throw new BadRequestAlertException("微信公众号[remove]操作发生错误","WXAccount",data.getWxaccountid().toString());
		return ResponseEntity.ok().body(data);
	}
	@GetMapping(value = "/{id}")
	public ResponseEntity<WXAccount> get(@Validated @PathVariable String id){
		WXAccount data=new WXAccount();
		data.setWxaccountid(id);;
		data=service.get(data);
		if(data==null)
			throw new BadRequestAlertException("微信公众号[get]操作发生错误","WXAccount",id.toString());
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/create")
	public ResponseEntity<WXAccount> create(@Validated @RequestBody WXAccount data){
		boolean bRt=service.create(data);
		if(!bRt)
			throw new BadRequestAlertException("微信公众号[create]操作发生错误","WXAccount",data.getWxaccountid().toString());
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/syncOrgUser")
	public ResponseEntity<WXAccount> syncOrgUser(@Validated @RequestBody WXAccount data){
		service.syncOrgUser(data);
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/update")
	public ResponseEntity<WXAccount> update(@Validated @RequestBody WXAccount data){
		boolean bRt=service.update(data);
		if(!bRt)
			throw new BadRequestAlertException("微信公众号[update]操作发生错误","WXAccount",data.getWxaccountid().toString());
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/getDraft")
	public ResponseEntity<WXAccount> getDraft(@Validated @RequestBody WXAccount data){
		boolean bRt=service.getDraft(data);
		if(!bRt)
			throw new BadRequestAlertException("微信公众号[getDraft]操作发生错误","WXAccount","");
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/checkKey")
	public ResponseEntity<WXAccount> checkKey(@Validated @RequestBody WXAccount data){
		boolean bRt=service.checkKey(data);
		if(!bRt)
			throw new BadRequestAlertException("微信公众号[checkKey]操作发生错误","WXAccount",data.getWxaccountid().toString());
		return ResponseEntity.ok().body(data);
	}
    @PostMapping(value="/searchdefault")
	public ResponseEntity<Page<WXAccount>> searchDefaultPage(@Validated @RequestBody WXAccountSearchFilter filter){
		Page<WXAccount> searchResult = service.searchDefault(filter);
		return ResponseEntity.ok().body(searchResult);
	}

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