package com.devjob.application.client;

import com.devjob.application.dto.JobInfo;
import com.devjob.common.dto.ApiResponse;
import com.devjob.common.exception.BusinessException;
import com.devjob.common.exception.ErrorCode;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;

@Component
public class JobClient {

    public JobClient(
            @Qualifier("devjob-job#com.devjob.application.client.JobHttpClient")
            JobHttpClient jobHttpClient) {
        this.jobHttpClient = jobHttpClient;
    }

    private final JobHttpClient jobHttpClient;

    public JobInfo getJob(Long jobId) {
        ApiResponse<JobInfo> response = jobHttpClient.getJob(jobId);

        if (response == null || response.data() == null) {
            throw new BusinessException(ErrorCode.JOB_NOT_FOUND);
        }
        return response.data();
    }
}
