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.web.bind.annotation.*

@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);
    }

    /**
     * FP-MTMS Version Checklist | Functions Ref. No. 19 | v1.0.0 | 2026-07-17
     * Inventory search page only: latest inventory row per item, no baseUnit/uomId filter.
     */
    @GetMapping("/searchLatest/getRecordByPage")
    fun searchInventoriesByLatestInventory(
        @ModelAttribute request: SearchInventoryRequest,
    ): RecordsRes<InventoryInfo> {
        return inventoryService.searchInventoriesByLatestInventory(request)
    }

    @PostMapping("/import-bom")
    fun importInventory() {
        val reportResult = inventoryService.importInventoryExcel()
    }
}
