package org.micord.controller;

import org.micord.exceptions.FileNotModifiedException;
import org.micord.service.ApiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.io.FileNotFoundException;
import java.util.List;
import java.util.concurrent.CompletableFuture;

/**
 * REST Controller for API operations.
 */
@RestController
@RequestMapping("/api")
public class ApiController {

    @Autowired
    private ApiService apiService;

    @PostMapping("/block")
    public CompletableFuture<ResponseEntity<?>> block(@RequestBody List<String> ids) throws FileNotFoundException, FileNotModifiedException {
        return apiService.process("block", ids)
                .thenApply(ResponseEntity::ok);
    }

    @PostMapping("/unblock")
    public CompletableFuture<ResponseEntity<?>> unblock(@RequestBody List<String> ids) throws FileNotFoundException, FileNotModifiedException {
        return apiService.process("unblock", ids)
                .thenApply(ResponseEntity::ok);
    }

    @PostMapping("/removeFromSystem")
    public CompletableFuture<ResponseEntity<?>> removeFromSystem(@RequestBody List<String> ids) throws FileNotFoundException, FileNotModifiedException {
        return apiService.process("removeFromSystem", ids)
                .thenApply(ResponseEntity::ok);
    }

    @PostMapping("/removeFromCallList")
    public CompletableFuture<ResponseEntity<?>> removeFromCallList(@RequestBody List<String> ids) throws FileNotFoundException, FileNotModifiedException {
        return apiService.process("removeFromCallList", ids)
                .thenApply(ResponseEntity::ok);
    }

}