<?php

namespace App\Console\Commands;

use App\Models\Tenant;
use Illuminate\Console\Command;
use Stancl\Tenancy\Database\Models\Domain;

class CreateMerchant extends Command
{
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'create:merchant';

    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'Creates merchant with ';

    /**
     * Execute the console command.
     *
     * @return int
     */
    public function handle()
    {
        $uniqueName = 'test_'.random_int(1, 50000);
        $primary_domain = $uniqueName.'.dentos.ge';

        $tenant = Tenant::create([
            'tenancy_db_name' => $uniqueName,
            'name' => 'test',
            'unique_name' => $uniqueName,
        ]);

        Domain::create([
            'domain' => $primary_domain,
            'tenant_id' => $tenant->id,
        ]);

        return Command::SUCCESS;
    }
}
