package com.devjob.controller;

import com.devjob.dto.ApiResponse;
import com.devjob.dto.MemberJoinRequest;
import com.devjob.dto.MemberResponse;
import com.devjob.service.MemberService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 회원 API.
 *
 * - POST /api/members/join → 201 Created (이메일 중복이면 409 Conflict)
 */
@RestController
@RequestMapping("/api/members")
@RequiredArgsConstructor
public class MemberController {

    private final MemberService memberService;

    @PostMapping("/join")
    public ResponseEntity<ApiResponse<MemberResponse>> join(@RequestBody @Valid MemberJoinRequest req) {
        return ResponseEntity.status(HttpStatus.CREATED)
                .body(ApiResponse.ok(memberService.join(req)));
    }
}
