package com.nisum.mytime.controller;

import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;

import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.PathVariable;

import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import com.nisum.mytime.exception.handler.MyTimeException;
import com.nisum.mytime.model.Domains;
import com.nisum.mytime.service.DomainService;

import com.nisum.mytime.utils.MyTimeUtils;

/**
 * @author Vijay
 *
 */
@RestController
public class DomainController {

	@Autowired
	private DomainService domainService;

	@RequestMapping(value = "/domains", method = RequestMethod.POST, produces = MediaType.TEXT_PLAIN_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<String> addDomain(@RequestBody Domains domains)
			throws MyTimeException {
		String response=null;
        response=domainService.addDomains(domains);
        return new ResponseEntity<>(response, HttpStatus.OK);
	}
	
	@RequestMapping(value = "/domains", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<List<HashMap<Object, Object>>> getAccounts() throws MyTimeException {
		return new ResponseEntity<>(domainService.getAllDomains(), HttpStatus.OK);
	}

	@RequestMapping(value = "/domains", method = RequestMethod.DELETE, produces = MediaType.TEXT_PLAIN_VALUE)
	public ResponseEntity<String> deleteDomain(@RequestParam String domainId) throws MyTimeException {
		domainService.deleteDomain(domainId);
		return new ResponseEntity<>("Success", HttpStatus.OK);
	}

	
	@RequestMapping(value = "/domains", method = RequestMethod.PUT, produces = MediaType.TEXT_PLAIN_VALUE)
    public ResponseEntity<String> updateDomain(@RequestBody Domains domains) throws MyTimeException {
		String response=null;
        response=domainService.updateDomain(domains);
        return new ResponseEntity<>(response, HttpStatus.OK);
    }
}