<?php

namespace App\Http\Controllers\Api\V1;

use App\Helpers\ApiResponse;
use App\Http\Controllers\Controller;
use App\Services\VendorLedgerService;
use Illuminate\Http\Request;

class VendorLedgerController extends Controller
{
    public function __construct(
        private readonly VendorLedgerService $service
    ) {}

    /**
     * 거래처원장 목록 (거래처별 매출/수금 집계)
     */
    public function index(Request $request)
    {
        $params = $request->only([
            'search',
            'start_date',
            'end_date',
            'sort_by',
            'sort_dir',
            'per_page',
            'page',
        ]);

        $ledger = $this->service->index($params);

        return ApiResponse::success($ledger, __('message.fetched'));
    }

    /**
     * 거래처원장 요약 통계
     */
    public function summary(Request $request)
    {
        $params = $request->only([
            'start_date',
            'end_date',
        ]);

        $summary = $this->service->summary($params);

        return ApiResponse::success($summary, __('message.fetched'));
    }

    /**
     * 거래처원장 상세 (거래처별 거래 내역)
     */
    public function show(int $clientId, Request $request)
    {
        $params = $request->only([
            'start_date',
            'end_date',
        ]);

        $detail = $this->service->show($clientId, $params);

        return ApiResponse::success($detail, __('message.fetched'));
    }
}
