package com.sinosig.web.module.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.sinosig.web.module.service.CIDService;
import com.sinosig.web.module.domain.CID;
import com.sinosig.web.module.filter.*;

@RestController
@RequestMapping(value = "")
public class CIDController {
	@Autowired
    CIDService cidservice;


	@RequestMapping(method = RequestMethod.POST, value = "/cids/checkkey")
    public ResponseEntity<Boolean> checkKey(@RequestBody CID cid) {
        boolean b = cidservice.checkKey(cid);
        return ResponseEntity.status(HttpStatus.OK).body(b);
    }

	@RequestMapping(method = RequestMethod.POST, value = "/cids")
    public ResponseEntity<CID> create(@RequestBody CID cid) {
        CID cid2 = cidservice.create(cid);
        return ResponseEntity.status(HttpStatus.OK).body(cid2);
    }

	@RequestMapping(method = RequestMethod.GET, value = "/cids/{cid_id}")
    public ResponseEntity<CID> get(@PathVariable("cid_id") String cid_id) {
        CID cid = cidservice.get( cid_id);
        return ResponseEntity.status(HttpStatus.OK).body(cid);
    }

	@RequestMapping(method = RequestMethod.GET, value = "/cids/getdraft")
    public ResponseEntity<CID> getDraft() {
        //CID cid = cidservice.getDraft( cid_id);
        return ResponseEntity.status(HttpStatus.OK).body(new CID());
    }

	@RequestMapping(method = RequestMethod.PUT, value = "/cids/{cid_id}")
    public ResponseEntity<CID> update(@PathVariable("cid_id") String cid_id, @RequestBody CID cid) {
        CID cid2 = cidservice.update(cid_id, cid);
        return ResponseEntity.status(HttpStatus.OK).body(cid2);
    }

	@RequestMapping(method = RequestMethod.POST, value = "/cids/{cid_id}/save")
    public ResponseEntity<CID> save(@PathVariable("cid_id") String cid_id, @RequestBody CID cid) {
        CID cid2 = cidservice.save(cid_id, cid);
        return ResponseEntity.status(HttpStatus.OK).body(cid2);
    }

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

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


    public ResponseEntity<CID> createTemp(@PathVariable("cid_id") String cid_id, @RequestBody CID cid) {
        return null;
    }


    public ResponseEntity<CID> removeTemp(@PathVariable("cid_id") String cid_id, @RequestBody CID cid) {
        return null;
    }


    public ResponseEntity<CID> getMRSYXXX(@PathVariable("cid_id") String cid_id, @RequestBody CID cid) {
        return null;
    }


    public ResponseEntity<CID> getOrgNameByUser(@PathVariable("cid_id") String cid_id, @RequestBody CID cid) {
        return null;
    }


    public ResponseEntity<CID> removeTempMajor(@PathVariable("cid_id") String cid_id, @RequestBody CID cid) {
        return null;
    }


    public ResponseEntity<CID> getTempMajor(@PathVariable("cid_id") String cid_id, @RequestBody CID cid) {
        return null;
    }


    public ResponseEntity<CID> getDraftTemp(@PathVariable("cid_id") String cid_id, @RequestBody CID cid) {
        return null;
    }


    public ResponseEntity<CID> updateTempMajor(@PathVariable("cid_id") String cid_id, @RequestBody CID cid) {
        return null;
    }


    public ResponseEntity<CID> updateTemp(@PathVariable("cid_id") String cid_id, @RequestBody CID cid) {
        return null;
    }


    public ResponseEntity<CID> jSBF(@PathVariable("cid_id") String cid_id, @RequestBody CID cid) {
        return null;
    }


    public ResponseEntity<CID> getMRJQXXX(@PathVariable("cid_id") String cid_id, @RequestBody CID cid) {
        return null;
    }


    public ResponseEntity<CID> getTemp(@PathVariable("cid_id") String cid_id, @RequestBody CID cid) {
        return null;
    }


    public ResponseEntity<CID> getDraftTempMajor(@PathVariable("cid_id") String cid_id, @RequestBody CID cid) {
        return null;
    }


    public ResponseEntity<CID> getCPXHXX(@PathVariable("cid_id") String cid_id, @RequestBody CID cid) {
        return null;
    }


    public ResponseEntity<CID> createTempMajor(@PathVariable("cid_id") String cid_id, @RequestBody CID cid) {
        return null;
    }


}
