package com.zioinfo.signage.controller;

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

@RestController
@RequestMapping("/api/works")
@RequiredArgsConstructor
public class WorkController {
    private final WorkService service;

    @GetMapping
    public ApiResponse<List<WorkHistoryVo>> list(
            @RequestParam(required = false) String tenantCode,
            @RequestParam(required = false) Long storeId,
            @RequestParam(required = false) String status,
            @RequestParam(required = false) String workType) {
        return ApiResponse.ok(service.list(tenantCode, storeId, status, workType));
    }

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

    @PostMapping
    public ApiResponse<WorkHistoryVo> create(@RequestBody WorkHistoryVo v) {
        return ApiResponse.ok("작업 등록 완료", service.create(v));
    }

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

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