"""Tests for BigQuery variant."""

from __future__ import annotations

from sqlglot import expressions as exp

from ddlglot.variants.bigquery import BigQueryBuilder, create_bigquery


class TestBigQueryBuilder:
    """Tests for BigQuery builder."""

    def test_create_table_basic(self) -> None:
        """Test basic table creation."""
        sql = (
            create_bigquery()
            .name("project.dataset.users")
            .columns(("id", "INT64"), ("name", "STRING"))
            .sql()
        )
        assert "CREATE TABLE" in sql
        assert "project.dataset.users" in sql

    def test_primary_key(self) -> None:
        """Test PRIMARY KEY."""
        sql = (
            create_bigquery()
            .name("project.dataset.orders")
            .column("id", "INT64", pk=True, not_null=True)
            .sql()
        )
        assert "PRIMARY KEY" in sql

    def test_if_not_exists(self) -> None:
        """Test IF NOT EXISTS."""
        sql = (
            create_bigquery()
            .name("project.dataset.users")
            .column("id", "INT64")
            .if_not_exists()
            .sql()
        )
        assert "IF NOT EXISTS" in sql

    def test_fluent_chaining(self) -> None:
        """Test fluent method chaining."""
        builder = create_bigquery().name("test").column("id", "INT64")
        assert isinstance(builder, BigQueryBuilder)

    def test_to_ast(self) -> None:
        """Test to_ast returns exp.Create."""
        ast = create_bigquery().name("project.dataset.users").column("id", "INT64").to_ast()
        assert isinstance(ast, exp.Create)

    def test_pretty_print(self) -> None:
        """Test pretty printing."""
        sql = (
            create_bigquery()
            .name("project.dataset.users")
            .columns(("id", "INT64"), ("name", "STRING"))
            .sql(pretty=True)
        )
        assert "\n" in sql
