package com.realnet.stepperworkflow.Controllers;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.realnet.fnd.response.EntityResponse;
import com.realnet.stepperworkflow.Entity.Stepper_table_config;
import com.realnet.stepperworkflow.Services.Stepper_table_configService;

@RequestMapping(value = "/Stepper_table_config")
@CrossOrigin("*")
@RestController
public class Stepper_table_configController {
	@Autowired
	private Stepper_table_configService Service;

	@Value("${projectPath}")
	private String projectPath;

	@PostMapping("/Stepper_table_config")
	public Stepper_table_config Savedata(@RequestParam Integer stepperId, @RequestParam Integer tableId,
			@RequestParam String tableName) {
		Stepper_table_config save = Service.Savedata(stepperId, tableId, tableName);

		System.out.println("data saved..." + save + "\n");

		return save;
	}

	@PutMapping("/Stepper_table_config/{id}")
	public Stepper_table_config update(@RequestBody Stepper_table_config data, @PathVariable Integer id) {
		Stepper_table_config update = Service.update(data, id);
		System.out.println("data update..." + update);
		return update;
	}

//	get all with pagination
	@GetMapping("/Stepper_table_config/getall/page")
	public Page<Stepper_table_config> getall(@RequestParam(value = "page", required = false) Integer page,
			@RequestParam(value = "size", required = false) Integer size) {
		Pageable paging = PageRequest.of(page, size);
		Page<Stepper_table_config> get = Service.getAllWithPagination(paging);

		return get;

	}

	@GetMapping("/Stepper_table_config/tableId")
	public List<Stepper_table_config> getAll(@RequestParam Integer stepper_id, @RequestParam Integer table_id) {
		List<Stepper_table_config> get = Service.getAll(stepper_id, table_id);
		return get;
	}

	@GetMapping("/Stepper_table_config/stepId/{stepper_id}")
	public List<Stepper_table_config> getAll(@PathVariable Integer stepper_id) {
		List<Stepper_table_config> get = Service.getAll(stepper_id);
		return get;
	}

	@GetMapping("/Stepper_table_config")
	public List<Stepper_table_config> getdetails() {
		List<Stepper_table_config> get = Service.getdetails();
		return get;
	}
// get all without authentication 

	@GetMapping("/token/Stepper_table_config")
	public List<Stepper_table_config> getallwioutsec() {
		List<Stepper_table_config> get = Service.getdetails();
		return get;
	}

	@GetMapping("/Stepper_table_config/{id}")
	public Stepper_table_config getdetailsbyId(@PathVariable Integer id) {
		Stepper_table_config get = Service.getdetailsbyId(id);
		return get;
	}

	@DeleteMapping("/Stepper_table_config/{id}")
	public ResponseEntity<?> delete_by_id(@PathVariable Integer id) {
		Service.delete_by_id(id);
		return new ResponseEntity<>(new EntityResponse("Deleted"), HttpStatus.OK);

	}

}