package com.ffii.fpsms.modules.bag.web

import com.ffii.fpsms.modules.bag.service.BagService
import com.ffii.fpsms.modules.bag.web.model.BagConsumptionResponse
import com.ffii.fpsms.modules.bag.web.model.BagInfo
import com.ffii.fpsms.modules.bag.web.model.BagLotLineResponse
import com.ffii.fpsms.modules.bag.web.model.BagSummaryResponse
import com.ffii.fpsms.modules.bag.web.model.BagUsageRecordResponse
import com.ffii.fpsms.modules.bag.web.model.CreateJoBagConsumptionRequest
import com.ffii.fpsms.modules.master.web.models.MessageResponse
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.PathVariable
import org.springframework.web.bind.annotation.PostMapping
import org.springframework.web.bind.annotation.PutMapping
import org.springframework.web.bind.annotation.RequestBody
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

@RestController
@RequestMapping("/bag")
class BagController(
    private val bagService: BagService
) {

    @GetMapping("/bagInfo")
    fun getBagInfo(): List<BagInfo> {
        return bagService.getAllBagInfo()
    }

    @PostMapping("/createJoBagConsumption")
    fun createJoBagConsumption(@RequestBody request: CreateJoBagConsumptionRequest): MessageResponse {
        return bagService.createJoBagConsumption(request)
    }

    @GetMapping("/bagUsageRecords")
    fun getBagUsageRecords(): List<BagUsageRecordResponse> {
        return bagService.getAllBagUsageRecords()
    }

    @GetMapping("/bags")
    fun getBags(): List<BagSummaryResponse> =
        bagService.getBagSummaries()

    @GetMapping("/bags/{bagId}/lot-lines")
    fun getBagLotLines(@PathVariable bagId: Long): List<BagLotLineResponse> =
        bagService.getBagLotLines(bagId)

    @GetMapping("/lot-lines/{bagLotLineId}/consumptions")
    fun getBagConsumptions(@PathVariable bagLotLineId: Long): List<BagConsumptionResponse> =
        bagService.getBagConsumptions(bagLotLineId)

    @PutMapping("/by-item/{itemId}/soft-delete")
    fun softDeleteBagByItemId(@PathVariable itemId: Long): MessageResponse =
        bagService.softDeleteBagByItemId(itemId)
}
