package com.zioinfo.esn.controller;

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

@RestController
@RequestMapping("/api/firmware")
@RequiredArgsConstructor
public class FirmwareController {
    private final FirmwareService service;

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

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

    @PostMapping
    public ApiResponse<FirmwareVo> create(@RequestBody FirmwareVo v) {
        return ApiResponse.ok("펌웨어 등록 완료", service.create(v));
    }

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

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