"""Dealer Portal Phase 2: action-audit tables for the dealer-facing portal and
the staff-side admin credential management screen — same shape as the
existing vendor_portal_action_log / vendor_portal_admin_action_log tables.

Revision ID: 95ab56f2de59
Revises: 142a4473844f
Create Date: 2026-07-18 09:30:00.000000

"""
from typing import Sequence, Union

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


# revision identifiers, used by Alembic.
revision: str = '95ab56f2de59'
down_revision: Union[str, None] = '142a4473844f'
branch_labels: Union[str, Sequence[str], None] = None
depends_on: Union[str, Sequence[str], None] = None


def upgrade() -> None:
    op.create_table(
        'dealer_portal_action_log',
        sa.Column('action_id', postgresql.UUID(as_uuid=True), primary_key=True),
        sa.Column('dealer_id', sa.String(50), sa.ForeignKey('customer_master.customer_id'), nullable=False),
        sa.Column('action_type', sa.String(50), nullable=False),
        sa.Column('entity_type', sa.String(50)),
        sa.Column('entity_id', sa.String(50)),
        sa.Column('action_details', postgresql.JSONB),
        sa.Column('ip_address', sa.String(50)),
        sa.Column('created_at', sa.DateTime(timezone=True)),
    )

    op.create_table(
        'dealer_portal_admin_action_log',
        sa.Column('action_id', postgresql.UUID(as_uuid=True), primary_key=True),
        sa.Column('admin_user_id', postgresql.UUID(as_uuid=True), nullable=False),
        sa.Column('dealer_id', sa.String(50), sa.ForeignKey('customer_master.customer_id'), nullable=True),
        sa.Column('action_type', sa.String(50), nullable=False),
        sa.Column('action_details', postgresql.JSONB),
        sa.Column('ip_address', sa.String(50)),
        sa.Column('created_at', sa.DateTime(timezone=True)),
    )


def downgrade() -> None:
    op.drop_table('dealer_portal_admin_action_log')
    op.drop_table('dealer_portal_action_log')
