package edu.prlab.tyler.iotgateway.cloud.controllers;

import edu.prlab.tyler.iotgateway.cloud.pojo.Document;
import edu.prlab.tyler.iotgateway.cloud.services.DocumentService;
import org.springframework.core.io.InputStreamResource;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;

@RestController
@RequestMapping("/document")
public class DocumentController {

    private DocumentService documentService;

    public DocumentController(DocumentService documentService) {
        this.documentService = documentService;
    }

    @PostMapping
    public ResponseEntity<Document> uploadFile(@RequestPart MultipartFile file) throws IOException {
        System.out.println(file.getName());
        return documentService.add(file)
                .map(ResponseEntity::ok)
                .orElseGet(() -> ResponseEntity.noContent().build());
    }

//    @GetMapping("/{id}")
//    public ResponseEntity<InputStreamResource> getFile(@PathVariable(value = "id") Long id) {
//        return
//    }
}
