package com.zioinfo.signage.controller;

import com.zioinfo.signage.common.ApiResponse;
import com.zioinfo.signage.domain.ProductVo;
import com.zioinfo.signage.service.ProductService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/api/products")
@RequiredArgsConstructor
public class ProductController {
    private final ProductService service;

    @GetMapping
    public ApiResponse<List<ProductVo>> list(
            @RequestParam(required = false) String tenantCode,
            @RequestParam(required = false) Long storeId,
            @RequestParam(required = false) String keyword) {
        return ApiResponse.ok(service.list(tenantCode, storeId, keyword));
    }

    @GetMapping("/{id}")
    public ApiResponse<ProductVo> get(@PathVariable Long id) {
        return ApiResponse.ok(service.get(id));
    }

    @PostMapping
    public ApiResponse<ProductVo> create(@RequestBody ProductVo v) {
        return ApiResponse.ok("상품 등록 완료", service.create(v));
    }

    @PutMapping("/{id}")
    public ApiResponse<ProductVo> update(@PathVariable Long id, @RequestBody ProductVo v) {
        return ApiResponse.ok("상품 수정 완료", service.update(id, v));
    }

    @DeleteMapping("/{id}")
    public ApiResponse<Void> delete(@PathVariable Long id) {
        service.delete(id);
        return ApiResponse.ok("상품 삭제 완료", null);
    }
}
