package cn.ibizlab.r7.runtime.runtimemgr.r7rt_base.controller;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import com.alibaba.fastjson.JSONObject;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import com.alibaba.fastjson.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.PageRequest;
import cn.ibizlab.r7.runtime.runtimemgr.r7rt_base.service.LoginAccountPwdService;
import cn.ibizlab.r7.runtime.runtimemgr.r7rt_base.domain.LoginAccountPwd;
import cn.ibizlab.r7.runtime.runtimemgr.r7rt_base.filter.*;

@RestController
@RequestMapping(value = "")
public class LoginAccountPwdController {
	@Autowired
    LoginAccountPwdService loginaccountpwdservice;


	@RequestMapping(method = RequestMethod.POST, value = "/loginaccountpwds/checkkey")
    @PreAuthorize("@loginaccountpwd_pms.check('')")
    public ResponseEntity<Boolean> checkKey(@RequestBody LoginAccountPwd loginaccountpwd) {
        boolean b = loginaccountpwdservice.checkKey(loginaccountpwd);
        return ResponseEntity.status(HttpStatus.OK).body(b);
    }

	@RequestMapping(method = RequestMethod.PUT, value = "/loginaccountpwds/{loginaccountpwd_id}")
    @PreAuthorize("@loginaccountpwd_pms.check(#loginaccountpwd_id,'UPDATE')")
    public ResponseEntity<LoginAccountPwd> update(@PathVariable("loginaccountpwd_id") String loginaccountpwd_id, @RequestBody LoginAccountPwd loginaccountpwd) {
        LoginAccountPwd loginaccountpwd2 = loginaccountpwdservice.update(loginaccountpwd_id, loginaccountpwd);
        return ResponseEntity.status(HttpStatus.OK).body(loginaccountpwd2);
    }

	@RequestMapping(method = RequestMethod.PUT, value = "/api/loginaccountpwds/{loginaccountpwd_id}")
    @PreAuthorize("@loginaccountpwd_pms.check(#loginaccountpwd_id,'UPDATE')")
    public ResponseEntity<LoginAccountPwd> api_update(@PathVariable("loginaccountpwd_id") String loginaccountpwd_id, @RequestBody LoginAccountPwd loginaccountpwd) {
        LoginAccountPwd loginaccountpwd2 = loginaccountpwdservice.update(loginaccountpwd_id, loginaccountpwd);
        return ResponseEntity.status(HttpStatus.OK).body(loginaccountpwd2);
    }

	@RequestMapping(method = RequestMethod.DELETE, value = "/loginaccountpwds/{loginaccountpwd_id}")
    @PreAuthorize("@loginaccountpwd_pms.check(#loginaccountpwd_id,'DELETE')")
    public ResponseEntity<Boolean> remove(@PathVariable("loginaccountpwd_id") String loginaccountpwd_id) {
        boolean b = loginaccountpwdservice.remove( loginaccountpwd_id);
        return ResponseEntity.status(HttpStatus.OK).body(b);
    }

	@RequestMapping(method = RequestMethod.GET, value = "/loginaccountpwds/{loginaccountpwd_id}")
    @PreAuthorize("@loginaccountpwd_pms.check(#loginaccountpwd_id,'READ')")
    public ResponseEntity<LoginAccountPwd> get(@PathVariable("loginaccountpwd_id") String loginaccountpwd_id) {
        LoginAccountPwd loginaccountpwd = loginaccountpwdservice.get( loginaccountpwd_id);
        return ResponseEntity.status(HttpStatus.OK).body(loginaccountpwd);
    }

	@RequestMapping(method = RequestMethod.POST, value = "/loginaccountpwds/{loginaccountpwd_id}/save")
    @PreAuthorize("@loginaccountpwd_pms.check(#loginaccountpwd_id,'')")
    public ResponseEntity<LoginAccountPwd> save(@PathVariable("loginaccountpwd_id") String loginaccountpwd_id, @RequestBody LoginAccountPwd loginaccountpwd) {
        LoginAccountPwd loginaccountpwd2 = loginaccountpwdservice.save(loginaccountpwd_id, loginaccountpwd);
        return ResponseEntity.status(HttpStatus.OK).body(loginaccountpwd2);
    }

	@RequestMapping(method = RequestMethod.POST, value = "/loginaccountpwds")
    @PreAuthorize("@loginaccountpwd_pms.check('CREATE')")
    public ResponseEntity<LoginAccountPwd> create(@RequestBody LoginAccountPwd loginaccountpwd) {
        LoginAccountPwd loginaccountpwd2 = loginaccountpwdservice.create(loginaccountpwd);
        return ResponseEntity.status(HttpStatus.OK).body(loginaccountpwd2);
    }

	@RequestMapping(method = RequestMethod.GET, value = "/loginaccountpwds/getdraft")
    @PreAuthorize("@loginaccountpwd_pms.check('CREATE')")
    public ResponseEntity<LoginAccountPwd> getDraft() {
        //LoginAccountPwd loginaccountpwd = loginaccountpwdservice.getDraft( loginaccountpwd_id);
        return ResponseEntity.status(HttpStatus.OK).body(new LoginAccountPwd());
    }

    @RequestMapping(method= RequestMethod.GET , value="/loginaccountpwds/fetchdefault")
    @PreAuthorize("@loginaccountpwd_pms.check('READ')")
	public ResponseEntity<List<LoginAccountPwd>> fetchDefault(LoginAccountPwdSearchContext searchContext,Pageable pageable) {
        
        Page<LoginAccountPwd> page = loginaccountpwdservice.fetchDefault(searchContext);
        return ResponseEntity.status(HttpStatus.OK)
                .header("x-page", String.valueOf(pageable.getPageNumber()))
        		.header("x-per-page", String.valueOf(pageable.getPageSize()))
        		.header("x-total", String.valueOf(page.getTotalElements()))
        		.body(page.getContent());
    }


}
