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

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sa.ibiz.demo.demo.domain.LoginAccount;
import com.sa.ibiz.demo.demo.service.LoginAccountService;
import com.sa.ibiz.demo.demo.service.dto.LoginAccountSearchFilter;
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/loginaccount")
public class LoginAccountResource
{
	@Autowired
	private LoginAccountService service;


	@GetMapping(value = "/{id}")
	public ResponseEntity<LoginAccount> get(@Validated @PathVariable String id){
		LoginAccount data=new LoginAccount();
		data.setLoginaccountid(id);;
		data=service.get(data);
		if(data==null)
			throw new BadRequestAlertException("登录帐户[get]操作发生错误","LoginAccount",id.toString());
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/create")
	public ResponseEntity<LoginAccount> create(@Validated @RequestBody LoginAccount data){
		boolean bRt=service.create(data);
		if(!bRt)
			throw new BadRequestAlertException("登录帐户[create]操作发生错误","LoginAccount",data.getLoginaccountid().toString());
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/remove")
	public ResponseEntity<LoginAccount> remove(@Validated @RequestBody LoginAccount data){
		boolean bRt=service.remove(data);
		if(!bRt)
			throw new BadRequestAlertException("登录帐户[remove]操作发生错误","LoginAccount",data.getLoginaccountid().toString());
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/update")
	public ResponseEntity<LoginAccount> update(@Validated @RequestBody LoginAccount data){
		boolean bRt=service.update(data);
		if(!bRt)
			throw new BadRequestAlertException("登录帐户[update]操作发生错误","LoginAccount",data.getLoginaccountid().toString());
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/getHashMode")
	public ResponseEntity<LoginAccount> getHashMode(@Validated @RequestBody LoginAccount data){
		service.getHashMode(data);
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/saveHashMode")
	public ResponseEntity<LoginAccount> saveHashMode(@Validated @RequestBody LoginAccount data){
		service.saveHashMode(data);
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/checkKey")
	public ResponseEntity<LoginAccount> checkKey(@Validated @RequestBody LoginAccount data){
		boolean bRt=service.checkKey(data);
		if(!bRt)
			throw new BadRequestAlertException("登录帐户[checkKey]操作发生错误","LoginAccount",data.getLoginaccountid().toString());
		return ResponseEntity.ok().body(data);
	}
	@PostMapping(value = "/getDraft")
	public ResponseEntity<LoginAccount> getDraft(@Validated @RequestBody LoginAccount data){
		boolean bRt=service.getDraft(data);
		if(!bRt)
			throw new BadRequestAlertException("登录帐户[getDraft]操作发生错误","LoginAccount","");
		return ResponseEntity.ok().body(data);
	}
    @PostMapping(value="/searchdefault")
	public ResponseEntity<Page<LoginAccount>> searchDefaultPage(@Validated @RequestBody LoginAccountSearchFilter filter){
		Page<LoginAccount> searchResult = service.searchDefault(filter);
		return ResponseEntity.ok().body(searchResult);
	}

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