package com.bizofficer.subscription.courses;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;


@RestController
@Service
public class SelectMyCourseController {
	
	private static final Logger logger = Logger.getLogger(SelectMyCourseController.class);
	
	@Autowired
	private SelectMyCourseService serviceObj;
	
	@RequestMapping(value = {"/selectmycourse"}, method = {RequestMethod.GET})
	public ResponseEntity<Object> execute(@ModelAttribute("SpringWeb")ACoursesBean objBean) {
		
		try {

			logger.info("StudentId: "+objBean.getStudentId() );
			logger.info("CourseId: "+objBean.getCourseId());
			

				SelectMyCourseResponseBean responseObj = (SelectMyCourseResponseBean) (Object) serviceObj.execute(objBean);
				
				logger.info("Service ResponseTxt: "+responseObj.getResponseTxt());
				
				HttpHeaders headers = new HttpHeaders();
		        return ResponseEntity.ok().headers(headers).body(responseObj);

		        
		} catch (Exception e) {
			e.printStackTrace();
			/////return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).body(e);
		}
		
		return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
	}
	

	
	
}
