package com.zioinfo.signage.controller;

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

@RestController
@RequestMapping("/api/template-groups")
@RequiredArgsConstructor
public class TemplateGroupController {
    private final TemplateGroupService service;

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

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

    @PostMapping
    public ApiResponse<TemplateGroupVo> create(@RequestBody TemplateGroupVo v) {
        return ApiResponse.ok("템플릿 그룹 생성 완료", service.create(v));
    }

    @PutMapping("/{id}")
    public ApiResponse<TemplateGroupVo> update(@PathVariable Long id, @RequestBody TemplateGroupVo v) {
        return ApiResponse.ok("템플릿 그룹 수정 완료", service.update(id, v));
    }

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