package com.zioinfo.esn.controller;

import com.zioinfo.esn.common.ApiResponse;
import com.zioinfo.esn.domain.StoreVo;
import com.zioinfo.esn.service.StoreService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
import java.util.List;

@RestController
@RequestMapping("/api/stores")
@RequiredArgsConstructor
public class StoreController {
    private final StoreService service;

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

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

    @PostMapping
    public ApiResponse<StoreVo> create(@RequestBody StoreVo v) {
        return ApiResponse.ok("매장 생성 완료", service.create(v));
    }

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

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