<?php

namespace App\Http\Controllers\Api\V1;

use App\Helpers\ApiResponse;
use App\Http\Controllers\Controller;
use App\Http\Requests\BarobillSetting\SaveBarobillSettingRequest;
use App\Services\BarobillService;

class BarobillSettingController extends Controller
{
    public function __construct(
        private BarobillService $barobillService
    ) {}

    /**
     * 바로빌 설정 조회
     */
    public function show()
    {
        return ApiResponse::handle(function () {
            return $this->barobillService->getSetting();
        }, __('message.fetched'));
    }

    /**
     * 바로빌 설정 저장
     */
    public function save(SaveBarobillSettingRequest $request)
    {
        return ApiResponse::handle(function () use ($request) {
            return $this->barobillService->saveSetting($request->validated());
        }, __('message.saved'));
    }

    /**
     * 연동 테스트
     */
    public function testConnection()
    {
        return ApiResponse::handle(function () {
            return $this->barobillService->testConnection();
        }, __('message.barobill.connection_success'));
    }
}
