package com.zioinfo.esn.controller;

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

@RestController
@RequestMapping("/api/templates")
@RequiredArgsConstructor
public class TemplateController {
    private final TemplateService service;

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

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

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

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

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