<?php

namespace App\Domains\Admin\Controllers;

use App\Domains\Admin\Actions\CreateTenant\CreateTenantAction;
use App\Domains\Admin\Actions\CreateTenant\CreateTenantRequest;
use App\Scopes\CommonController;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;

class TenantCreateController extends CommonController
{
    public function __invoke(Request $request): JsonResponse
    {
        $action = new CreateTenantAction(new CreateTenantRequest(
            name: $request->input('name'),
            slug: $request->input('slug'),
            url: $request->input('url'),
        ));

        $response = $action->execute();

        return response()->json([
            'status' => $response->success ? 'success' : 'error',
            'message' => $response->message,
            'slug' => $response->slug,
        ]);
    }
}
