<?php

namespace App\Http\Controllers\Api\V1\Design;

use App\Helpers\ApiResponse;
use App\Http\Controllers\Controller;
use App\Http\Requests\Design\ModelVersion\CreateDraftRequest;
use App\Services\Design\ModelVersionService;

class ModelVersionController extends Controller
{
    public function __construct(
        protected ModelVersionService $service
    ) {}

    public function index(int $modelId)
    {
        return ApiResponse::handle(fn () => $this->service->listByModel($modelId), __('message.fetched'));
    }

    public function createDraft(CreateDraftRequest $request, int $modelId)
    {
        return ApiResponse::handle(function () use ($request, $modelId) {
            $payload = $request->validated();

            return $this->service->createDraft($modelId, $payload);
        }, __('message.created'));
    }

    public function release(int $versionId)
    {
        return ApiResponse::handle(fn () => $this->service->release($versionId), __('message.updated'));
    }
}
