"""point center: point tasks and withdrawals

Revision ID: 057_point_center
Revises: 056_mall_limits
Create Date: 2026-06-21
"""

import sqlalchemy as sa
from alembic import op


revision = "057_point_center"
down_revision = "056_mall_limits"
branch_labels = None
depends_on = None


def upgrade() -> None:
    op.create_table(
        "point_tasks",
        sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
        sa.Column("user_id", sa.BigInteger(), nullable=False),
        sa.Column("task_type", sa.String(length=32), nullable=False),
        sa.Column("reward_points", sa.Integer(), nullable=False),
        sa.Column("submitted_value", sa.String(length=255), nullable=True),
        sa.Column("checkin_date", sa.Date(), nullable=True),
        sa.Column("checkin_points", sa.Integer(), nullable=True),
        sa.Column("completed_at", sa.DateTime(timezone=True), nullable=True),
        sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
        sa.Column("updated_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
        sa.ForeignKeyConstraint(["user_id"], ["users.id"], ondelete="CASCADE"),
        sa.PrimaryKeyConstraint("id"),
        sa.UniqueConstraint("user_id", "task_type", "checkin_date", name="uq_point_task_user_type_date"),
    )
    op.create_index(op.f("ix_point_tasks_user_id"), "point_tasks", ["user_id"], unique=False)
    op.create_index(op.f("ix_point_tasks_task_type"), "point_tasks", ["task_type"], unique=False)
    op.create_index(op.f("ix_point_tasks_checkin_date"), "point_tasks", ["checkin_date"], unique=False)

    op.create_table(
        "point_withdrawals",
        sa.Column("id", sa.Integer(), autoincrement=True, nullable=False),
        sa.Column("user_id", sa.BigInteger(), nullable=False),
        sa.Column("points_amount", sa.Integer(), nullable=False),
        sa.Column("fee_points", sa.Integer(), nullable=False),
        sa.Column("credited_cents", sa.Integer(), nullable=False),
        sa.Column("status", sa.String(length=32), nullable=False),
        sa.Column("remark", sa.String(length=255), nullable=True),
        sa.Column("processed_at", sa.DateTime(timezone=True), nullable=True),
        sa.Column("created_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
        sa.Column("updated_at", sa.DateTime(timezone=True), server_default=sa.func.now(), nullable=False),
        sa.ForeignKeyConstraint(["user_id"], ["users.id"], ondelete="CASCADE"),
        sa.PrimaryKeyConstraint("id"),
    )
    op.create_index(op.f("ix_point_withdrawals_user_id"), "point_withdrawals", ["user_id"], unique=False)
    op.create_index(op.f("ix_point_withdrawals_status"), "point_withdrawals", ["status"], unique=False)


def downgrade() -> None:
    op.drop_index(op.f("ix_point_withdrawals_status"), table_name="point_withdrawals")
    op.drop_index(op.f("ix_point_withdrawals_user_id"), table_name="point_withdrawals")
    op.drop_table("point_withdrawals")
    op.drop_index(op.f("ix_point_tasks_checkin_date"), table_name="point_tasks")
    op.drop_index(op.f("ix_point_tasks_task_type"), table_name="point_tasks")
    op.drop_index(op.f("ix_point_tasks_user_id"), table_name="point_tasks")
    op.drop_table("point_tasks")
