package com.ffii.fpsms.modules.master.web

import com.ffii.core.exception.NotFoundException
import com.ffii.fpsms.modules.master.entity.QcCategory
import com.ffii.fpsms.modules.master.entity.projections.QcCategoryCombo
import com.ffii.fpsms.modules.master.service.QcCategoryService
import com.ffii.fpsms.modules.qc.entity.projection.QcCategoryInfo
import org.springframework.web.bind.annotation.*

@RestController
@RequestMapping("/qcCategories")
class QcCategoryController(
    private val qcCategoryService: QcCategoryService
) {
    @GetMapping
    fun allQcCategories(): List<QcCategory> {
        return qcCategoryService.allQcCategories()
    }

    @GetMapping("/combo")
    fun getQcCategoryCombo(): List<QcCategoryCombo> {
        return qcCategoryService.getQcCategoryCombo();
    }

    @GetMapping("/items")
    fun getQcCategoryByTemplate(@RequestParam itemId: Long, @RequestParam(defaultValue = "IQC") type: String): QcCategoryInfo {
        return qcCategoryService.getQcCategoryInfoByMapping(itemId, type) ?: throw NotFoundException()
    }
}