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.UserRoleDataService;
import cn.ibizlab.r7.runtime.runtimemgr.r7rt_base.domain.UserRoleData;
import cn.ibizlab.r7.runtime.runtimemgr.r7rt_base.filter.*;

@RestController
@RequestMapping(value = "")
public class UserRoleDataController {
	@Autowired
    UserRoleDataService userroledataservice;


	@RequestMapping(method = RequestMethod.POST, value = "/userroledata/checkkey")
    @PreAuthorize("@userroledata_pms.check('')")
    public ResponseEntity<Boolean> checkKey(@RequestBody UserRoleData userroledata) {
        boolean b = userroledataservice.checkKey(userroledata);
        return ResponseEntity.status(HttpStatus.OK).body(b);
    }

	@RequestMapping(method = RequestMethod.GET, value = "/userroledata/getdraft")
    @PreAuthorize("@userroledata_pms.check('CREATE')")
    public ResponseEntity<UserRoleData> getDraft() {
        //UserRoleData userroledata = userroledataservice.getDraft( userroledata_id);
        return ResponseEntity.status(HttpStatus.OK).body(new UserRoleData());
    }

	@RequestMapping(method = RequestMethod.GET, value = "/userroledata/{userroledata_id}/getuserroledataapi")
    @PreAuthorize("@userroledata_pms.check(#userroledata_id,'READ')")
    public ResponseEntity<UserRoleData> getUserRoleDataAPI(@PathVariable("userroledata_id") String userroledata_id, @RequestBody UserRoleData userroledata) {
        UserRoleData userroledata2 = userroledataservice.getUserRoleDataAPI(userroledata_id, userroledata);
        return ResponseEntity.status(HttpStatus.OK).body(userroledata2);
    }

	@RequestMapping(method = RequestMethod.GET, value = "/userroledata/{userroledata_id}")
    @PreAuthorize("@userroledata_pms.check(#userroledata_id,'READ')")
    public ResponseEntity<UserRoleData> get(@PathVariable("userroledata_id") String userroledata_id) {
        UserRoleData userroledata = userroledataservice.get( userroledata_id);
        return ResponseEntity.status(HttpStatus.OK).body(userroledata);
    }

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

	@RequestMapping(method = RequestMethod.POST, value = "/userroledata/{userroledata_id}/haspermissiongv")
    @PreAuthorize("@userroledata_pms.check(#userroledata_id,'')")
    public ResponseEntity<UserRoleData> hasPermissionGV(@PathVariable("userroledata_id") String userroledata_id, @RequestBody UserRoleData userroledata) {
        UserRoleData userroledata2 = userroledataservice.hasPermissionGV(userroledata_id, userroledata);
        return ResponseEntity.status(HttpStatus.OK).body(userroledata2);
    }

	@RequestMapping(method = RequestMethod.POST, value = "/userroledata")
    @PreAuthorize("@userroledata_pms.check('CREATE')")
    public ResponseEntity<UserRoleData> create(@RequestBody UserRoleData userroledata) {
        UserRoleData userroledata2 = userroledataservice.create(userroledata);
        return ResponseEntity.status(HttpStatus.OK).body(userroledata2);
    }

	@RequestMapping(method = RequestMethod.PUT, value = "/userroledata/{userroledata_id}")
    @PreAuthorize("@userroledata_pms.check(#userroledata_id,'UPDATE')")
    public ResponseEntity<UserRoleData> update(@PathVariable("userroledata_id") String userroledata_id, @RequestBody UserRoleData userroledata) {
        UserRoleData userroledata2 = userroledataservice.update(userroledata_id, userroledata);
        return ResponseEntity.status(HttpStatus.OK).body(userroledata2);
    }

	@RequestMapping(method = RequestMethod.PUT, value = "/api/userroledata/{userroledata_id}")
    @PreAuthorize("@userroledata_pms.check(#userroledata_id,'UPDATE')")
    public ResponseEntity<UserRoleData> api_update(@PathVariable("userroledata_id") String userroledata_id, @RequestBody UserRoleData userroledata) {
        UserRoleData userroledata2 = userroledataservice.update(userroledata_id, userroledata);
        return ResponseEntity.status(HttpStatus.OK).body(userroledata2);
    }

	@RequestMapping(method = RequestMethod.POST, value = "/userroledata/{userroledata_id}/haspermissionev")
    @PreAuthorize("@userroledata_pms.check(#userroledata_id,'')")
    public ResponseEntity<UserRoleData> hasPermissionEV(@PathVariable("userroledata_id") String userroledata_id, @RequestBody UserRoleData userroledata) {
        UserRoleData userroledata2 = userroledataservice.hasPermissionEV(userroledata_id, userroledata);
        return ResponseEntity.status(HttpStatus.OK).body(userroledata2);
    }

	@RequestMapping(method = RequestMethod.POST, value = "/userroledata/{userroledata_id}/save")
    @PreAuthorize("@userroledata_pms.check(#userroledata_id,'')")
    public ResponseEntity<UserRoleData> save(@PathVariable("userroledata_id") String userroledata_id, @RequestBody UserRoleData userroledata) {
        UserRoleData userroledata2 = userroledataservice.save(userroledata_id, userroledata);
        return ResponseEntity.status(HttpStatus.OK).body(userroledata2);
    }

	@RequestMapping(method = RequestMethod.POST, value = "/userroledata/{userroledata_id}/syncdata")
    @PreAuthorize("@userroledata_pms.check(#userroledata_id,'')")
    public ResponseEntity<UserRoleData> syncData(@PathVariable("userroledata_id") String userroledata_id, @RequestBody UserRoleData userroledata) {
        UserRoleData userroledata2 = userroledataservice.syncData(userroledata_id, userroledata);
        return ResponseEntity.status(HttpStatus.OK).body(userroledata2);
    }

    @RequestMapping(method= RequestMethod.GET , value="/userroledata/fetchdefault")
    @PreAuthorize("@userroledata_pms.check('READ')")
	public ResponseEntity<List<UserRoleData>> fetchDefault(UserRoleDataSearchContext searchContext,Pageable pageable) {
        
        Page<UserRoleData> page = userroledataservice.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());
    }


}
