-- Tabela de domínios principais
CREATE TABLE IF NOT EXISTS domains (
    id SERIAL PRIMARY KEY,
    name VARCHAR(255) UNIQUE NOT NULL,
    hostinger_id VARCHAR(255),
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

-- Tabela de subdomínios (entradas DNS)
CREATE TABLE IF NOT EXISTS subdomains (
    id SERIAL PRIMARY KEY,
    domain_id INTEGER REFERENCES domains(id) ON DELETE CASCADE,
    subdomain VARCHAR(255) NOT NULL,
    full_domain VARCHAR(255) UNIQUE NOT NULL,
    type VARCHAR(10) DEFAULT 'A',
    value VARCHAR(255) NOT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    UNIQUE(domain_id, subdomain)
);

-- Tabela de branding (identidade visual)
CREATE TABLE IF NOT EXISTS branding (
    id SERIAL PRIMARY KEY,
    subdomain_id INTEGER UNIQUE REFERENCES subdomains(id) ON DELETE CASCADE,
    logo_url TEXT,
    primary_color VARCHAR(50) DEFAULT '#FF6B00',
    secondary_color VARCHAR(50) DEFAULT '#1A1A1A',
    title VARCHAR(255),
    description TEXT,
    favicon_url TEXT,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
