package ru.micord.ervu.account_applications.controller;

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

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import ru.micord.ervu.account_applications.model.StatusResponse;
import ru.micord.ervu.account_applications.service.UserApplicationListService;

/**
 * @author gulnaz
 */
@RestController
public class UserApplicationController {
  private final UserApplicationListService applicationService;

  public UserApplicationController(UserApplicationListService applicationService) {
    this.applicationService = applicationService;
  }


  @PostMapping("/status/batch")
  public List<StatusResponse> getBatchStatuses(@RequestBody List<Long> appNumbers) {
    Map<Long, String> statuses = applicationService.getStatusesBatch(appNumbers);
    return appNumbers.stream()
        .map(appNumber -> new StatusResponse(
            appNumber,
            statuses.get(appNumber)
        ))
        .collect(Collectors.toList());
  }
}
