class AssetTrendController {

    @ApiOperation(value = "View the asset trends(daily min/max) over the period of last 1 month", response = Iterable.class)
    @GetMapping(path = "/v1/trend/minmax")
    public ResponseEntity<Object> getMinMaxAssetCount(@RequestParam(name = "ag", required = true) String assetGroup,
            @RequestParam(name = "type", required = true) String type,
            @RequestParam(name = "from", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date fromDate,
            @RequestParam(name = "to", required = false) @DateTimeFormat(pattern = "yyyy-MM-dd") Date toDate,
            @RequestParam(name = "domain", required = false) String domain) {
        try {
            Date from = fromDate; 
            Date to = toDate;
            if (from == null && to == null) {
                Calendar cal = Calendar.getInstance();
                cal.setTimeZone(TimeZone.getTimeZone("UTC"));
                to = cal.getTime();
                cal.add(Calendar.DATE, Constants.NEG_THIRTY);
                from = cal.getTime();
            }
            Map<String, Object> response = new LinkedHashMap<>();
            response.put("ag", assetGroup);
            response.put("type", type);
            List<Map<String, Object>> trendList = assetService.getAssetMinMax(assetGroup, type, from, to);
            response.put("trend", trendList);
            return ResponseUtils.buildSucessResponse(response);
        } catch (Exception e) {
            return ResponseUtils.buildFailureResponse(e);
        }
    }

}