package com.ffii.fpsms.modules.stock.web

import com.ffii.core.response.RecordsRes
import com.ffii.fpsms.modules.stock.entity.projection.InventoryInfo
import com.ffii.fpsms.modules.stock.service.InventoryService
import com.ffii.fpsms.modules.stock.web.model.SearchInventoryRequest
import org.springframework.core.io.ByteArrayResource
import org.springframework.core.io.Resource
import org.springframework.http.HttpHeaders
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.*
import java.time.LocalDate

@RestController
@RequestMapping("/inventory")
class InventoryController(
    private val inventoryService: InventoryService,
) {
    @GetMapping("/list")
    fun allInventories(): List<InventoryInfo> {
        return inventoryService.allInventories()
    }

    @GetMapping("/getRecordByPage")
    fun allInventoriesByPage(@ModelAttribute request: SearchInventoryRequest): RecordsRes<InventoryInfo> {
        return inventoryService.allInventoriesByPage(request);
    }

    @PostMapping("/import-bom")
    fun importInventory() {
        val reportResult = inventoryService.importInventoryExcel()
//        val filename = "bom_excel_issue_log_${LocalDate.now()}.xlsx"

//        return ResponseEntity.ok()
//            .header(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"$filename\"")
//            .header(HttpHeaders.CONTENT_TYPE, "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet")
//            .body(ByteArrayResource(reportResult))
    }
}