package com.ibiz.web.external.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.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 com.ibiz.web.external.service.SYXBJService;
import com.ibiz.web.external.domain.SYXBJ;
import com.ibiz.web.external.filter.*;

@RestController
@RequestMapping(value = "")
public class SYXBJController {
	@Autowired
    SYXBJService syxbjservice;


	@RequestMapping(method = RequestMethod.POST, value = "/syxbjs/{syxbj_id}/save")
    public ResponseEntity<SYXBJ> save(@PathVariable("syxbj_id") String syxbj_id, @RequestBody SYXBJ syxbj) {
        SYXBJ syxbj2 = syxbjservice.save(syxbj_id, syxbj);
        return ResponseEntity.status(HttpStatus.OK).body(syxbj2);
    }

	@RequestMapping(method = RequestMethod.DELETE, value = "/syxbjs/{syxbj_id}")
    public ResponseEntity<Boolean> remove(@PathVariable("syxbj_id") String syxbj_id) {
        boolean b = syxbjservice.remove( syxbj_id);
        return ResponseEntity.status(HttpStatus.OK).body(b);
    }

	@RequestMapping(method = RequestMethod.GET, value = "/syxbjs/getdraft")
    public ResponseEntity<SYXBJ> getDraft() {
        //SYXBJ syxbj = syxbjservice.getDraft( syxbj_id);
        return ResponseEntity.status(HttpStatus.OK).body(new SYXBJ());
    }

	@RequestMapping(method = RequestMethod.POST, value = "/syxbjs/checkkey")
    public ResponseEntity<Boolean> checkKey(@RequestBody SYXBJ syxbj) {
        boolean b = syxbjservice.checkKey(syxbj);
        return ResponseEntity.status(HttpStatus.OK).body(b);
    }

	@RequestMapping(method = RequestMethod.PUT, value = "/syxbjs/{syxbj_id}")
    public ResponseEntity<SYXBJ> update(@PathVariable("syxbj_id") String syxbj_id, @RequestBody SYXBJ syxbj) {
        SYXBJ syxbj2 = syxbjservice.update(syxbj_id, syxbj);
        return ResponseEntity.status(HttpStatus.OK).body(syxbj2);
    }

	@RequestMapping(method = RequestMethod.POST, value = "/syxbjs")
    public ResponseEntity<SYXBJ> create(@RequestBody SYXBJ syxbj) {
        SYXBJ syxbj2 = syxbjservice.create(syxbj);
        return ResponseEntity.status(HttpStatus.OK).body(syxbj2);
    }

	@RequestMapping(method = RequestMethod.GET, value = "/syxbjs/{syxbj_id}")
    public ResponseEntity<SYXBJ> get(@PathVariable("syxbj_id") String syxbj_id) {
        SYXBJ syxbj = syxbjservice.get( syxbj_id);
        return ResponseEntity.status(HttpStatus.OK).body(syxbj);
    }

    @RequestMapping(method= RequestMethod.GET , value="/syxbjs/fetchdefault")
	public ResponseEntity<List<SYXBJ>> fetchDefault(SYXBJSearchContext searchContext,Pageable pageable) {
        
        searchContext.setPageable(pageable);
        Page<SYXBJ> page = syxbjservice.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());
    }


}
