package pwc.taxtech.atms.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
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.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import pwc.taxtech.atms.dto.OperationResultDto;
import pwc.taxtech.atms.dto.arearegion.AreaRegionDto;
import pwc.taxtech.atms.dto.arearegion.AreaRegionInfo;
import pwc.taxtech.atms.service.impl.AreaRegionServiceImpl;

import java.util.List;

@RestController
@RequestMapping("/api/v1/areaRegion/")
public class AreaRegionController {

    private static Logger logger = LoggerFactory.getLogger(AreaRegionController.class);

    @Autowired
    private AreaRegionServiceImpl areaRegionService;

    @SuppressWarnings("rawtypes")
//    @ApiOperation(value = "Adds the specified area.")
    @RequestMapping(value = "add", method = RequestMethod.POST)
    public @ResponseBody
    OperationResultDto add(@RequestBody AreaRegionInfo areaRegionInfo) {
        logger.info("/api/v1/areaRegion/add");
        return areaRegionService.add(areaRegionInfo);
    }

    @SuppressWarnings("rawtypes")
//    @ApiOperation(value = "Update the specified area.")
    @RequestMapping(value = "update", method = RequestMethod.POST)
    public @ResponseBody
    OperationResultDto update(@RequestBody AreaRegionInfo areaRegionInfo) {
        logger.info("/api/v1/areaRegion/update");
        return areaRegionService.update(areaRegionInfo);
    }

//    @ApiOperation(value = "Get cities")
    @RequestMapping(value = "getCities", method = RequestMethod.GET)
    public @ResponseBody
    List<AreaRegionDto> getCities(@RequestParam(name = "parentID") String parentId) {
        logger.info("/api/v1/areaRegion/getProvinces");
        return areaRegionService.getCities(parentId);
    }

//    @ApiOperation(value = "Get Provinces")
    @RequestMapping(value = "getProvinces", method = RequestMethod.GET)
    public @ResponseBody
    List<AreaRegionDto> getProvinces() {
        logger.info("/api/v1/areaRegion/getCities");
        return areaRegionService.getProvinces();
    }
}