package com.zioinfo.signage.controller;

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

@RestController
@RequestMapping("/api/regions")
@RequiredArgsConstructor
public class RegionController {
    private final RegionService service;

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

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

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

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

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