"""Create system_settings table.

Revision ID: 0010_system_settings
Revises: 0009_sequences
Create Date: 2026-07-04
"""

from __future__ import annotations

from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects import postgresql

revision: str = "0010_system_settings"
down_revision: Union[str, None] = "0009_sequences"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    op.create_table(
        "system_settings",
        sa.Column("id", postgresql.UUID(as_uuid=True), primary_key=True),
        sa.Column("company_name", sa.String(200), nullable=False),
        sa.Column("company_legal_form", sa.String(50), nullable=True),
        sa.Column("company_street", sa.String(255), nullable=False),
        sa.Column("company_city", sa.String(100), nullable=False),
        sa.Column("company_zip", sa.String(20), nullable=False),
        sa.Column("company_country", sa.String(2), nullable=False),
        sa.Column("tax_number", sa.String(50), nullable=True),
        sa.Column("vat_id", sa.String(50), nullable=True),
        sa.Column("iban", sa.String(34), nullable=True),
        sa.Column("bic", sa.String(11), nullable=True),
        sa.Column("bank_name", sa.String(100), nullable=True),
        sa.Column("ceo", sa.String(100), nullable=True),
        sa.Column("trade_register", sa.String(100), nullable=True),
        sa.Column("default_currency_id", postgresql.UUID(as_uuid=True),
                  sa.ForeignKey("currencies.id", ondelete="SET NULL"), nullable=True),
        sa.Column("default_tax_id", postgresql.UUID(as_uuid=True),
                  sa.ForeignKey("tax_rates.id", ondelete="SET NULL"), nullable=True),
        sa.Column("invoice_prefix", sa.String(20), nullable=False, server_default="RE-"),
        sa.Column("quote_prefix", sa.String(20), nullable=False, server_default="AN-"),
        sa.Column("payment_terms_days", sa.Integer, nullable=False, server_default="14"),
        sa.Column("tenant_id", postgresql.UUID(as_uuid=True), nullable=False, index=True),
        sa.Column("created_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.func.now()),
        sa.Column("updated_at", sa.DateTime(timezone=True), nullable=False, server_default=sa.func.now()),
        sa.Column("deleted_at", sa.DateTime(timezone=True), nullable=True),
    )
    op.create_index("ix_system_settings_tenant", "system_settings", ["tenant_id"])


def downgrade() -> None:
    op.drop_index("ix_system_settings_tenant", table_name="system_settings")
    op.drop_table("system_settings")
