"""Initial migration

Revision ID: 6d31ffcb8ae0
Revises: 
Create Date: 2025-05-01 21:22:59.505106

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa


# revision identifiers, used by Alembic.
revision: str = '6d31ffcb8ae0'
down_revision: Union[str, None] = None
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###

    # op.execute("DROP TYPE IF EXISTS adminCompanyUserRoleEnum")
    # op.execute("DROP TYPE IF EXISTS CompanyPlanEnum")
    # op.execute("DROP TYPE IF EXISTS departmentenum")
    # op.execute("DROP TYPE IF EXISTS CompanyUserRoleEnum")
    
    op.create_table('admin_users',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('full_name', sa.String(length=100), nullable=False),
    sa.Column('email', sa.String(length=100), nullable=False),
    sa.Column('hashed_password', sa.String(length=255), nullable=False),
    sa.Column('role', sa.Enum('SUPER_ADMIN', 'SUPPORT_STAFF', 'BILLING_ADMIN', name='adminCompanyUserRoleEnum'), nullable=False),
    sa.Column('is_active', sa.Boolean(), nullable=True),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=True),
    sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_admin_users_email'), 'admin_users', ['email'], unique=True)
    op.create_index(op.f('ix_admin_users_id'), 'admin_users', ['id'], unique=False)
    op.create_table('companies',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('company_name', sa.String(length=100), nullable=False),
    sa.Column('legal_name', sa.String(length=150), nullable=True),
    sa.Column('bio', sa.String(length=255), nullable=True),
    sa.Column('address', sa.Text(), nullable=True),
    sa.Column('home_country', sa.String(length=100), nullable=True),
    sa.Column('company_logo_url', sa.String(length=255), nullable=True),
    sa.Column('has_branches', sa.Boolean(), nullable=False),
    sa.Column('users_count', sa.Integer(), nullable=True),
    sa.Column('email', sa.String(length=100), nullable=False),
    sa.Column('phone_number', sa.String(length=20), nullable=True),
    sa.Column('db_name', sa.String(length=100), nullable=True),
    sa.Column('db_host', sa.String(length=100), nullable=True),
    sa.Column('db_port', sa.String(length=6), nullable=True),
    sa.Column('plan', sa.Enum('FREE', 'STARTER', 'PRO', 'ENTERPRISE', name='CompanyPlanEnum'), nullable=False),
    sa.Column('trial_ends_at', sa.DateTime(timezone=True), nullable=True),
    sa.Column('next_billing_date', sa.DateTime(timezone=True), nullable=True),
    sa.Column('is_active', sa.Boolean(), nullable=False),
    sa.Column('settings', sa.JSON(), nullable=True),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
    sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
    sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index(op.f('ix_companies_db_name'), 'companies', ['db_name'], unique=True)
    op.create_index(op.f('ix_companies_email'), 'companies', ['email'], unique=True)
    op.create_index(op.f('ix_companies_id'), 'companies', ['id'], unique=False)
    op.create_table('gl_details',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('date', sa.DateTime(), nullable=False),
    sa.Column('gl_number', sa.String(length=50), nullable=False),
    sa.Column('account_name', sa.String(length=255), nullable=False),
    sa.Column('category', sa.String(length=50), nullable=False),
    sa.Column('description', sa.String(length=500), nullable=True),
    sa.Column('customer', sa.String(length=255), nullable=True),
    sa.Column('vendor', sa.String(length=255), nullable=True),
    sa.Column('debit', sa.Numeric(precision=14, scale=2), nullable=False),
    sa.Column('credit', sa.Numeric(precision=14, scale=2), nullable=False),
    sa.PrimaryKeyConstraint('id')
    )
    op.create_index('ix_gl_details_date', 'gl_details', ['date'], unique=False)
    op.create_index('ix_gl_details_gl_number', 'gl_details', ['gl_number'], unique=False)
    op.create_index(op.f('ix_gl_details_id'), 'gl_details', ['id'], unique=False)
    op.create_table('users',
    sa.Column('id', sa.Integer(), nullable=False),
    sa.Column('company_name', sa.String(length=100), nullable=False),
    sa.Column('company_id', sa.Integer(), nullable=False),
    sa.Column('full_name', sa.String(length=100), nullable=False),
    sa.Column('email', sa.String(length=100), nullable=False),
    sa.Column('hashed_password', sa.String(length=255), nullable=False),
    sa.Column('department', sa.Enum('HR', 'FINANCE', 'MARKETING', 'SALES', 'CEO', 'CFO', 'ADMINISTRATION', name='departmentenum'), nullable=False),
    sa.Column('role', sa.Enum('ADMIN', 'ANALYST', 'VIEWER', name='CompanyUserRoleEnum'), nullable=False),
    sa.Column('permissions', sa.JSON(), nullable=True),
    sa.Column('is_active', sa.Boolean(), nullable=False),
    sa.Column('created_at', sa.DateTime(timezone=True), server_default=sa.text('now()'), nullable=False),
    sa.Column('updated_at', sa.DateTime(timezone=True), nullable=True),
    sa.Column('deleted_at', sa.DateTime(timezone=True), nullable=True),
    sa.PrimaryKeyConstraint('id'),
    sa.UniqueConstraint('department')
    )
    op.create_index(op.f('ix_users_email'), 'users', ['email'], unique=True)
    op.create_index(op.f('ix_users_id'), 'users', ['id'], unique=False)
    # ### end Alembic commands ###


def downgrade() -> None:
    # ### commands auto generated by Alembic - please adjust! ###
    op.drop_index(op.f('ix_users_id'), table_name='users')
    op.drop_index(op.f('ix_users_email'), table_name='users')
    op.drop_table('users')
    op.drop_index(op.f('ix_gl_details_id'), table_name='gl_details')
    op.drop_index('ix_gl_details_gl_number', table_name='gl_details')
    op.drop_index('ix_gl_details_date', table_name='gl_details')
    op.drop_table('gl_details')
    op.drop_index(op.f('ix_companies_id'), table_name='companies')
    op.drop_index(op.f('ix_companies_email'), table_name='companies')
    op.drop_index(op.f('ix_companies_db_name'), table_name='companies')
    op.drop_table('companies')
    op.drop_index(op.f('ix_admin_users_id'), table_name='admin_users')
    op.drop_index(op.f('ix_admin_users_email'), table_name='admin_users')
    op.drop_table('admin_users')
    # ### end Alembic commands ###
