<?php

namespace App\Http\Controllers\Api\V1;

use App\Helpers\ApiResponse;
use App\Http\Controllers\Controller;
use App\Http\Requests\Bidding\BiddingFilterRequest;
use App\Http\Requests\Bidding\BiddingStatusRequest;
use App\Http\Requests\Bidding\BiddingStoreRequest;
use App\Http\Requests\Bidding\BiddingUpdateRequest;
use App\Http\Requests\Bidding\BulkDeleteRequest;
use App\Services\Bidding\BiddingService;

class BiddingController extends Controller
{
    public function __construct(private BiddingService $service) {}

    /**
     * 입찰 목록 조회
     */
    public function index(BiddingFilterRequest $request)
    {
        return ApiResponse::handle(fn () => $this->service->index($request->validated()));
    }

    /**
     * 입찰 통계 조회
     */
    public function stats()
    {
        return ApiResponse::handle(fn () => $this->service->stats());
    }

    /**
     * 입찰 생성 (견적에서 전환 포함)
     */
    public function store(BiddingStoreRequest $request)
    {
        return ApiResponse::handle(fn () => $this->service->store($request->validated()), 'message.created');
    }

    /**
     * 입찰 단건 조회
     */
    public function show(int $id)
    {
        return ApiResponse::handle(fn () => $this->service->show($id));
    }

    /**
     * 입찰 수정
     */
    public function update(BiddingUpdateRequest $request, int $id)
    {
        return ApiResponse::handle(fn () => $this->service->update($id, $request->validated()), 'message.updated');
    }

    /**
     * 입찰 삭제
     */
    public function destroy(int $id)
    {
        return ApiResponse::handle(fn () => $this->service->destroy($id), 'message.deleted');
    }

    /**
     * 입찰 일괄 삭제
     */
    public function bulkDestroy(BulkDeleteRequest $request)
    {
        return ApiResponse::handle(fn () => $this->service->bulkDestroy($request->validated()['ids']), 'message.deleted');
    }

    /**
     * 입찰 상태 변경
     */
    public function updateStatus(BiddingStatusRequest $request, int $id)
    {
        return ApiResponse::handle(fn () => $this->service->updateStatus($id, $request->validated()['status']), 'message.updated');
    }
}
