package com.caliverse.admin.domain.api;

import com.caliverse.admin.domain.request.EventRequest;
import com.caliverse.admin.domain.response.EventResponse;
import com.caliverse.admin.domain.service.EventService;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@Tag(name = "이벤트", description = "이벤트 조회 및 발송 관리 메뉴 api")
@RestController
@RequiredArgsConstructor
@RequestMapping("/api/v1/event")
public class EventController {

    private final EventService eventService;
    // 리스트 조회
    @GetMapping("/list")
    public ResponseEntity<EventResponse> getList(
            @RequestParam Map<String, String> requestParam){

        return ResponseEntity.ok().body(eventService.getList(requestParam));
    }
    // 상세 조회
    @GetMapping("/detail/{id}")
    public ResponseEntity<EventResponse> getDetail(
            @PathVariable("id") Long id){

        return ResponseEntity.ok().body(eventService.getDetail(id));
    }
    @PostMapping
    public ResponseEntity<EventResponse> postEvent(
            @RequestBody EventRequest eventRequest){

        return ResponseEntity.ok().body(eventService.postEvent(eventRequest));
    }
    @PutMapping("/{id}")
    public ResponseEntity<EventResponse> updateEvent(
            @PathVariable("id")Long id, @RequestBody EventRequest eventRequest){

        return ResponseEntity.ok().body(eventService.updateEvent(id, eventRequest));
    }
    @DeleteMapping("/delete")
    public ResponseEntity<EventResponse> deleteEvent(
            @RequestBody EventRequest eventRequest){

        return ResponseEntity.ok().body(eventService.deleteEvent(eventRequest));
    }
    @PostMapping("/item")
    public ResponseEntity<EventResponse> getItem(
            @RequestBody Map<String, String> item) {
        return ResponseEntity.ok().body(eventService.getMetaItem(item.get("item")));
    }
}
