package com.bizofficer.apiweb.testdetail;

import java.util.List;

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 ResultTestController {
	
	@Autowired
	private ResultMockTestService resultMockTestServiceObj;
	
	@Autowired
	private ResultSelfTestAPIService resultSelfTestAPIServiceObj;

	////testresultview?testSession=9c38c5a7-3e17-4dfe-bbc8-0b80b17b24d0
	@SuppressWarnings("unchecked")
	@RequestMapping(value = {"/testresultview"}, method = RequestMethod.GET)
	public ResponseEntity<Object> execute(@ModelAttribute("SpringWeb")BeanTesting objBean) {
		
		try {
			
			
			System.out.println("ResultTestController Test Session: "+objBean.getTestSession() );
			List<TestingPageBean> list = null;
			// Mock Test ************************************************
			if(objBean.getTestSession()!=null && objBean.getTestSession().length()>3 && "mt".equalsIgnoreCase(objBean.getTestSession().substring(0, 2)) ) {
				objBean.setTestSession(objBean.getTestSession().substring(2));
				list = (List<TestingPageBean>) (Object) resultMockTestServiceObj.doExecute(objBean);

			// Topic Test ***********************************************	
//			}else if(objBean.getTestType()!=null && objBean.getTestType()==2) {
//				list = (List<TestingPageBean>) (Object) topicTestAPIServiceObj.doExecute(objBean);
			
			// Self Test ************************************************	
			}else if(objBean.getTestSession()!=null && objBean.getTestSession().length()>3 && "st".equalsIgnoreCase(objBean.getTestSession().substring(0, 2)) ) {
				objBean.setTestSession(objBean.getTestSession().substring(2));
				list = (List<TestingPageBean>) (Object) resultSelfTestAPIServiceObj.doExecute(objBean);
				
			}
			
			HttpHeaders headers = new HttpHeaders();
	        ////headers.add("Responded", "UserController");
	        return ResponseEntity.ok().headers(headers).body(list);
			
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
	}
	

	
	
}
