<?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()
    {
        $setting = $this->barobillService->getSetting();

        return ApiResponse::handle(
            data: $setting,
            message: __('message.fetched')
        );
    }

    /**
     * 바로빌 설정 저장
     */
    public function save(SaveBarobillSettingRequest $request)
    {
        $setting = $this->barobillService->saveSetting($request->validated());

        return ApiResponse::handle(
            data: $setting,
            message: __('message.saved')
        );
    }

    /**
     * 연동 테스트
     */
    public function testConnection()
    {
        $result = $this->barobillService->testConnection();

        return ApiResponse::handle(
            data: $result,
            message: __('message.barobill.connection_success')
        );
    }
}
