package kr.itn.itnhub.memo;

import jakarta.validation.Valid;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/** 기관관리 상세의 업무메모 탭이 부르는 엔드포인트. */
@RestController
public class WorkMemoController {

    private final WorkMemoService memoService;

    public WorkMemoController(WorkMemoService memoService) {
        this.memoService = memoService;
    }

    @GetMapping("/api/orgs/{id}/memos")
    public List<WorkMemo> list(@PathVariable Long id) {
        return memoService.list(id);
    }

    @PostMapping("/api/orgs/{id}/memos")
    public WorkMemo create(@PathVariable Long id, @Valid @RequestBody MemoRequest request) {
        return memoService.create(id, request);
    }

    @ResponseStatus(HttpStatus.NO_CONTENT)
    @DeleteMapping("/api/orgs/{id}/memos/{memoId}")
    public void delete(@PathVariable Long id, @PathVariable Long memoId) {
        memoService.delete(id, memoId);
    }
}
