from __future__ import annotations

from datetime import date, timedelta
from typing import Any


class WbsMilestonesMixin:
    """Standard 5 Milestones generator for construction project timeline."""

    @staticmethod
    def _build_milestones(
        p1_end: date,
        p2_end: date,
        p3_start: date,
        p3_end: date,
        p3_days: int,
        p4_end: date,
    ) -> list[dict[str, Any]]:
        milestones = [
            {
                "milestone_name": "Mốc 1: Khởi công & Bàn giao mặt bằng thi công",
                "target_date": p1_end.isoformat(),
                "sort_order": 1,
                "status": "pending",
                "description": "Hoàn tất bàn giao tim mốc, hồ sơ pháp lý khởi công và biện pháp ATLĐ.",
            },
            {
                "milestone_name": "Mốc 2: Nghiệm thu hoàn thành phần Móng & Hạ tầng ngầm",
                "target_date": p2_end.isoformat(),
                "sort_order": 2,
                "status": "pending",
                "description": "Nghiệm thu chuyển bước thi công kết cấu thân và giải ngân IPC Đợt 1.",
            },
            {
                "milestone_name": "Mốc 3: Hoàn thành Kết cấu thân / Cất nóc",
                "target_date": (p3_start + timedelta(days=p3_days // 2)).isoformat(),
                "sort_order": 3,
                "status": "pending",
                "description": "Đổ bê tông sàn tầng mái và hoàn tất nghiệm thu cốt thép dầm sàn.",
            },
            {
                "milestone_name": "Mốc 4: Nghiệm thu kỹ thuật & Chạy thử liên động (M&E)",
                "target_date": p3_end.isoformat(),
                "sort_order": 4,
                "status": "pending",
                "description": "Chạy thử hệ thống điện nước, PCCC và hoàn thiện mặt ngoài.",
            },
            {
                "milestone_name": "Mốc 5: Bàn giao công trình & Quyết toán hợp đồng",
                "target_date": p4_end.isoformat(),
                "sort_order": 5,
                "status": "pending",
                "description": "Bàn giao chìa khóa trao tay cho Chủ đầu tư và thanh toán đợt cuối.",
            },
        ]

        return milestones
