package com.r11.tools.controller;

import com.r11.tools.mappers.RequestHistoryMapper;
import com.r11.tools.model.RequestHistory;
import com.r11.tools.model.RequestHistoryDTO;
import com.r11.tools.service.RequestHistoryService;
import lombok.AllArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.stream.Collectors;

/**
 * It's the REST api for {@link RequestHistory}
 * @author Gabriel Modzelewski
 * @author Mikołaj Widła
 */
@RestController
@RequestMapping(path = "/api/event")
@AllArgsConstructor
@CrossOrigin(origins = "*")
public class RequestHistoryController {
    private final RequestHistoryService service;
    private final RequestHistoryMapper mapper;

    /**
     * Returns the list of Events.
     * @param uuid unique id of message list
     * @return list of {@link RequestHistory}
     */
    @GetMapping(path = "/{uuid}")
    public ResponseEntity<List<RequestHistoryDTO>> getLastDay(@PathVariable String uuid){
        List<RequestHistoryDTO> requestHistory = service.getHistoryRecordsByUUID(
                uuid
        ).stream()
                .map(mapper::requestHistoryToRequestHistoryDTO)
                .collect(Collectors.toList());
        return ResponseEntity.ok(requestHistory);
    }
}

