<?php

namespace App\Controllers;

class Api extends BaseController
{
    public function checkDomain()
    {
        $db = \Config\Database::connect();
        
        $json = $this->request->getJSON();
        if (!$json || !isset($json->full_domain)) {
            return $this->response->setJSON(['error' => 'Invalid request']);
        }
        
        $fullDomain = strtolower($json->full_domain);
        
        $exists = $db->table('domains')->where('full_domain', $fullDomain)->countAllResults();
        
        return $this->response->setJSON([
            'available' => $exists === 0,
            'domain' => $fullDomain
        ]);
    }
}
