package com.devjob.notification.controller;

import com.devjob.common.dto.ApiResponse;
import com.devjob.notification.dto.EmailRequest;
import com.devjob.notification.dto.NotificationResponse;
import com.devjob.notification.service.NotificationService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import java.util.List;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 알림 API. devjob-notification 서비스, 8084번 포트.
 * - POST /notifications/email : 이메일 발송 요청 (devjob-application이 EP27에서 호출)
 * - GET  /notifications/my    : 내 알림 이력 조회
 */
@Tag(name = "알림")
@RestController
@RequestMapping("/notifications")
@RequiredArgsConstructor
public class NotificationController {

    private final NotificationService notificationService;

    @Operation(summary = "이메일 발송 요청")
    @PostMapping("/email")
    public ResponseEntity<ApiResponse<NotificationResponse>> sendEmail(@RequestBody @Valid EmailRequest req) {
        return ResponseEntity.status(HttpStatus.CREATED).body(ApiResponse.ok(notificationService.sendEmail(req)));
    }

    @Operation(summary = "내 알림 이력 조회")
    @GetMapping("/my")
    public ApiResponse<List<NotificationResponse>> myNotifications(@RequestHeader("X-User-Id") Long userId) {
        return ApiResponse.ok(notificationService.findMy(userId));
    }
}
