package com.devjob.controller;

import com.devjob.dto.ApiResponse;
import com.devjob.dto.JobCreateRequest;
import com.devjob.dto.JobResponse;
import com.devjob.service.JobService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

/**
 * 채용 공고 API.
 *
 * - GET  /api/jobs/{id}              → @PathVariable, 단건 조회
 * - GET  /api/jobs?status=OPEN&...   → @RequestParam, 목록/검색
 * - POST /api/jobs                   → @RequestBody + @Valid, 생성
 */
@RestController
@RequestMapping("/api/jobs")
@RequiredArgsConstructor
public class JobController {

    private final JobService jobService;

    @PostMapping
    public ApiResponse<JobResponse> create(@RequestBody @Valid JobCreateRequest req) {
        return ApiResponse.ok(jobService.create(req));
    }

    @GetMapping("/{id}")
    public ApiResponse<JobResponse> getJob(@PathVariable Long id) {
        return ApiResponse.ok(jobService.findById(id).orElse(null));
    }

    @GetMapping
    public ApiResponse<Page<JobResponse>> getJobs(
            @RequestParam(defaultValue = "OPEN") String status,
            @RequestParam(defaultValue = "0") int page,
            @RequestParam(defaultValue = "10") int size) {
        return ApiResponse.ok(jobService.findByStatus(status, page, size));
    }
}
