<?php

namespace App\Http\Controllers\Api\V1\Admin\Draw;

use App\Models\Draw;
use App\Lottery\ErrorCode;
use App\Support\ApiResponse;
use App\Support\ApiMessage;
use Illuminate\Http\Request;
use Illuminate\Http\JsonResponse;
use App\Http\Controllers\Controller;
use App\Services\Draw\DrawDestroyService;

final class AdminDrawDestroyController extends Controller
{
    public function __construct(
        private readonly DrawDestroyService $service,
    ) {}

    public function __invoke(Request $request, Draw $draw): JsonResponse
    {
        try {
            $this->service->destroy($draw);
        } catch (\RuntimeException $e) {
            return ApiMessage::runtimeErrorResponse($request, $e);
        }

        return ApiResponse::success(['deleted' => true]);
    }
}
