"""Adds boolean column editable to incident cost type model

Revision ID: 678b759299ff
Revises: c86be389dc1a
Create Date: 2021-03-15 17:04:16.060713

"""
from alembic import op
import sqlalchemy as sa

from dispatch.incident_cost_type.models import IncidentCostType


# revision identifiers, used by Alembic.
revision = "678b759299ff"
down_revision = "c86be389dc1a"
branch_labels = None
depends_on = None


def upgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.alter_column(
        "incident_cost", "amount", existing_type=sa.NUMERIC(precision=10, scale=2), nullable=True
    )
    op.add_column("incident_cost_type", sa.Column("editable", sa.Boolean(), nullable=True))
    op.alter_column("incident_cost_type", "description", existing_type=sa.VARCHAR(), nullable=True)
    # ### end Alembic commands ###

    # we create a default incident cost type for response cost
    op.bulk_insert(
        IncidentCostType.__table__,
        [
            {
                "name": "Response Cost",
                "description": "Cost associated with handling an incident.",
                "details": {},
                "default": True,
                "editable": False,
            }
        ],
    )


def downgrade():
    # ### commands auto generated by Alembic - please adjust! ###
    op.alter_column("incident_cost_type", "description", existing_type=sa.VARCHAR(), nullable=False)
    op.drop_column("incident_cost_type", "editable")
    op.alter_column(
        "incident_cost", "amount", existing_type=sa.NUMERIC(precision=10, scale=2), nullable=False
    )
    # ### end Alembic commands ###
