package com.zioinfo.mes.tracking;

import com.zioinfo.mes.common.ApiResponse;
import com.zioinfo.mes.inventory.MesInventoryTxn;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * LOT 추적 API — 정/역 추적 + 이력. 조회 Viewer+.
 */
@RestController
@RequestMapping("/api/mes/tracking")
@RequiredArgsConstructor
public class TrackingController {

    private final TrackingService service;

    @GetMapping("/lot/{lotNo}/history")
    public ApiResponse<List<MesInventoryTxn>> history(@PathVariable String lotNo) {
        return ApiResponse.ok(service.lotHistory(lotNo));
    }

    /** 역추적 — 산출 LOT 에 투입된 자재. */
    @GetMapping("/lot/{lotNo}/backward")
    public ApiResponse<Map<String, Object>> backward(@PathVariable String lotNo) {
        return ApiResponse.ok(service.backward(lotNo));
    }

    /** 정추적 — 자재 LOT 가 사용된 작업지시·산출 LOT. */
    @GetMapping("/lot/{lotNo}/forward")
    public ApiResponse<Map<String, Object>> forward(@PathVariable String lotNo) {
        return ApiResponse.ok(service.forward(lotNo));
    }
}
