"""Ajoute le suivi des demandes de travaux et devis."""
from alembic import op
import sqlalchemy as sa

revision = "fb2c3d4e5f6a"
down_revision = "fa1b2c3d4e5f"
branch_labels = None
depends_on = None

def upgrade():
    op.create_table("work_requests",
        sa.Column("id", sa.Integer(), primary_key=True), sa.Column("title", sa.String(255), nullable=False),
        sa.Column("description", sa.Text(), nullable=False), sa.Column("status", sa.String(40), nullable=False),
        sa.Column("execution_mode", sa.String(30), nullable=False), sa.Column("priority", sa.String(20), nullable=False),
        sa.Column("equipment_id", sa.Integer(), sa.ForeignKey("equipments.id")), sa.Column("service_id", sa.Integer(), sa.ForeignKey("services.id")),
        sa.Column("company_id", sa.Integer(), sa.ForeignKey("companies.id")), sa.Column("created_by_id", sa.Integer(), sa.ForeignKey("users.id"), nullable=False),
        sa.Column("chief_decision", sa.String(20)), sa.Column("department_decision", sa.String(20)), sa.Column("chief_decision_date", sa.Date()), sa.Column("department_decision_date", sa.Date()),
        sa.Column("planned_date", sa.Date()), sa.Column("completed_date", sa.Date()), sa.Column("actual_minutes", sa.Integer()), sa.Column("parts_cost", sa.Numeric(10, 2)), sa.Column("notes", sa.Text()),
        sa.Column("created_at", sa.DateTime()), sa.Column("updated_at", sa.DateTime()),
    )
    op.create_table("work_request_quotes", sa.Column("id", sa.Integer(), primary_key=True), sa.Column("request_id", sa.Integer(), sa.ForeignKey("work_requests.id", ondelete="CASCADE"), nullable=False), sa.Column("company_id", sa.Integer(), sa.ForeignKey("companies.id")), sa.Column("reference", sa.String(100)), sa.Column("amount_ht", sa.Numeric(10, 2)), sa.Column("amount_ttc", sa.Numeric(10, 2)), sa.Column("quote_date", sa.Date()), sa.Column("valid_until", sa.Date()), sa.Column("status", sa.String(20), nullable=False), sa.Column("file_path", sa.String(500)), sa.Column("notes", sa.Text()))
    op.create_table("work_request_events", sa.Column("id", sa.Integer(), primary_key=True), sa.Column("request_id", sa.Integer(), sa.ForeignKey("work_requests.id", ondelete="CASCADE"), nullable=False), sa.Column("user_id", sa.Integer(), sa.ForeignKey("users.id"), nullable=False), sa.Column("old_status", sa.String(40)), sa.Column("new_status", sa.String(40), nullable=False), sa.Column("comment", sa.Text()), sa.Column("created_at", sa.DateTime()))

def downgrade():
    op.drop_table("work_request_events"); op.drop_table("work_request_quotes"); op.drop_table("work_requests")
