package com.zioinfo.esn.controller;

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

@RestController
@RequestMapping("/api/tenants")
@RequiredArgsConstructor
public class TenantController {
    private final TenantService service;

    @GetMapping
    public ApiResponse<List<TenantVo>> list() {
        return ApiResponse.ok(service.list());
    }

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

    @PostMapping
    public ApiResponse<TenantVo> create(@RequestBody TenantVo v) {
        return ApiResponse.ok("테넌트 생성 완료", service.create(v));
    }

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

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