"""Intègre le workflow des travaux aux interventions."""
from alembic import op
import sqlalchemy as sa

revision = "fd4e5f6a7b8c"
down_revision = "fc3d4e5f6a7b"
branch_labels = None
depends_on = None


def upgrade():
    op.add_column("interventions", sa.Column("execution_mode", sa.String(30), nullable=False, server_default="interne"))
    op.add_column("interventions", sa.Column("department_service_id", sa.Integer(), sa.ForeignKey("services.id"), nullable=True))
    op.add_column("interventions", sa.Column("department_request_date", sa.Date(), nullable=True))
    op.add_column("interventions", sa.Column("chief_validation_date", sa.Date(), nullable=True))
    op.add_column("interventions", sa.Column("department_validation_date", sa.Date(), nullable=True))
    op.add_column("interventions", sa.Column("quote_status", sa.String(30), nullable=False, server_default="non_requis"))
    op.add_column("interventions", sa.Column("quote_reference", sa.String(100), nullable=True))
    op.add_column("interventions", sa.Column("quote_amount_ht", sa.Float(), nullable=True))
    op.add_column("interventions", sa.Column("quote_amount_ttc", sa.Float(), nullable=True))
    op.add_column("interventions", sa.Column("quote_date", sa.Date(), nullable=True))
    op.add_column("interventions", sa.Column("quote_valid_until", sa.Date(), nullable=True))
    op.add_column("interventions", sa.Column("work_notes", sa.Text(), nullable=True))


def downgrade():
    for name in ("work_notes", "quote_valid_until", "quote_date", "quote_amount_ttc", "quote_amount_ht", "quote_reference", "quote_status", "department_validation_date", "chief_validation_date", "department_request_date", "department_service_id", "execution_mode"):
        op.drop_column("interventions", name)
