"""Create company_profiles table for Settings -> Company Profile.

Revision ID: 035_company_profile
Revises: 034_gs_detail_description
Create Date: 2026-08-15
"""

from typing import Sequence, Union

import sqlalchemy as sa
from alembic import op

revision: str = "035_company_profile"
down_revision: Union[str, None] = "034_gs_detail_description"
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    conn = op.get_bind()
    inspector = sa.inspect(conn)
    tables = set(inspector.get_table_names())
    if "company_profiles" in tables:
        return

    op.create_table(
        "company_profiles",
        sa.Column("id", sa.String(length=36), primary_key=True),
        sa.Column("company_id", sa.String(length=36), nullable=False),
        sa.Column("company_name", sa.String(length=200), nullable=False),
        sa.Column("date_of_establishment", sa.Date(), nullable=True),
        sa.Column("company_tagline", sa.String(length=255), nullable=True),
        sa.Column("business_type", sa.String(length=40), nullable=True),
        sa.Column("industry_type", sa.String(length=40), nullable=True),
        sa.Column("currency", sa.String(length=10), nullable=False, server_default="PKR"),
        sa.Column("registration_number", sa.String(length=100), nullable=True),
        sa.Column("fiscal_year_start", sa.String(length=20), nullable=False, server_default="july"),
        sa.Column("tax_number", sa.String(length=100), nullable=True),
        sa.Column("time_zone", sa.String(length=50), nullable=False, server_default="Asia/Karachi"),
        sa.Column("website", sa.String(length=255), nullable=True),
        sa.Column("default_language", sa.String(length=10), nullable=False, server_default="en"),
        sa.Column("logo_path", sa.String(length=500), nullable=True),
        sa.Column("address", sa.Text(), nullable=False),
        sa.Column("country", sa.String(length=10), nullable=False, server_default="PK"),
        sa.Column("state_province", sa.String(length=100), nullable=False, server_default=""),
        sa.Column("city", sa.String(length=100), nullable=False, server_default=""),
        sa.Column("postal_code", sa.String(length=20), nullable=False, server_default=""),
        sa.Column("phone", sa.String(length=50), nullable=True),
        sa.Column("alternate_phone", sa.String(length=50), nullable=True),
        sa.Column("email", sa.String(length=255), nullable=True),
        sa.Column("alternate_email", sa.String(length=255), nullable=True),
        sa.Column("fax", sa.String(length=50), nullable=True),
        sa.Column("number_of_employees", sa.String(length=50), nullable=True),
        sa.Column("description", sa.Text(), nullable=True),
        sa.Column("notes", sa.Text(), nullable=True),
        sa.Column("facebook_url", sa.String(length=255), nullable=True),
        sa.Column("twitter_url", sa.String(length=255), nullable=True),
        sa.Column("linkedin_url", sa.String(length=255), nullable=True),
        sa.Column("instagram_url", sa.String(length=255), nullable=True),
        sa.Column("youtube_url", sa.String(length=255), nullable=True),
        sa.Column("whatsapp", sa.String(length=50), nullable=True),
        sa.Column("created_at", sa.DateTime(), nullable=False),
        sa.Column("updated_at", sa.DateTime(), nullable=False),
        sa.ForeignKeyConstraint(["company_id"], ["companies.id"], ondelete="CASCADE"),
        sa.UniqueConstraint("company_id", name="uq_company_profiles_company_id"),
    )
    op.create_index("ix_company_profiles_company_id", "company_profiles", ["company_id"])


def downgrade() -> None:
    conn = op.get_bind()
    inspector = sa.inspect(conn)
    tables = set(inspector.get_table_names())
    if "company_profiles" in tables:
        op.drop_table("company_profiles")
