"""add_data_sources_table

Revision ID: b008datasources
Revises: b007remediation
Create Date: 2026-02-09 14:00:00.000000

"""
from typing import Sequence, Union

from alembic import op
import sqlalchemy as sa
from sqlalchemy.dialects.postgresql import UUID, JSONB


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


def upgrade() -> None:
    """Create data_sources table."""
    op.create_table(
        'data_sources',
        sa.Column('id', UUID(as_uuid=True), primary_key=True),
        sa.Column('name', sa.String(), unique=True, nullable=False),
        sa.Column('display_name', sa.String(), nullable=False),
        sa.Column('type', sa.String(), nullable=False),
        sa.Column('url', sa.String(), nullable=True),
        sa.Column('description', sa.Text(), nullable=True),
        sa.Column('is_enabled', sa.Boolean(), server_default='true'),
        sa.Column('last_sync_at', sa.DateTime(), nullable=True),
        sa.Column('last_sync_status', sa.String(), nullable=True),
        sa.Column('last_sync_stats', JSONB(), nullable=True),
        sa.Column('sync_frequency', sa.String(), nullable=True),
        sa.Column('config', JSONB(), nullable=True),
        sa.Column('created_at', sa.DateTime(), server_default=sa.func.now()),
    )
    op.create_index('ix_data_sources_type', 'data_sources', ['type'])
    op.create_index('ix_data_sources_is_enabled', 'data_sources', ['is_enabled'])


def downgrade() -> None:
    """Drop data_sources table."""
    op.drop_index('ix_data_sources_is_enabled', table_name='data_sources')
    op.drop_index('ix_data_sources_type', table_name='data_sources')
    op.drop_table('data_sources')
