"""
PPM Table Schemas

اسکیماهای جدول ماژول مدیریت پرتفولیو و برنامه.
"""


# ═══════════════════════════════════════════════════
# Portfolio Table
# ═══════════════════════════════════════════════════

PORTFOLIO_TABLE = {
    "id": "ppm_portfolio_table",
    "title": "پرتفولیوها",
    "endpoint": "/api/v1/ppm/portfolios/",
    "columns": [
        {"key": "code", "label": "کد", "sortable": True, "width": 100},
        {"key": "name", "label": "نام", "sortable": True, "width": 200},
        {
            "key": "status", "label": "وضعیت", "sortable": True, "width": 110,
            "badge_map": {
                "draft": {"label": "پیش‌نویس", "color": "gray"},
                "active": {"label": "فعال", "color": "green"},
                "on_hold": {"label": "متوقف", "color": "yellow"},
                "closed": {"label": "بسته‌شده", "color": "red"},
                "archived": {"label": "آرشیوشده", "color": "purple"},
            },
        },
        {"key": "owner_name", "label": "مالک", "width": 150},
        {
            "key": "risk_tolerance", "label": "تحمل ریسک", "sortable": True, "width": 100,
            "badge_map": {
                "low": {"label": "پایین", "color": "green"},
                "medium": {"label": "متوسط", "color": "yellow"},
                "high": {"label": "بالا", "color": "red"},
            },
        },
        {"key": "total_budget", "label": "بودجه کل", "type": "currency", "width": 140},
        {"key": "allocated_budget", "label": "تخصیص‌یافته", "type": "currency", "width": 140},
        {"key": "start_date", "label": "شروع", "sortable": True, "type": "date_jalali", "width": 120},
        {"key": "end_date", "label": "پایان", "sortable": True, "type": "date_jalali", "width": 120},
        {"key": "review_cycle", "label": "دوره بازبینی", "width": 100},
        {"key": "created_at", "label": "تاریخ ایجاد", "sortable": True, "type": "date_jalali", "width": 130},
    ],
    "filters": [
        {"key": "status", "label": "وضعیت", "type": "select", "options": [
            {"value": "draft", "label": "پیش‌نویس"},
            {"value": "active", "label": "فعال"},
            {"value": "on_hold", "label": "متوقف"},
            {"value": "closed", "label": "بسته‌شده"},
            {"value": "archived", "label": "آرشیوشده"},
        ]},
        {"key": "risk_tolerance", "label": "تحمل ریسک", "type": "select", "options": [
            {"value": "low", "label": "پایین"},
            {"value": "medium", "label": "متوسط"},
            {"value": "high", "label": "بالا"},
        ]},
        {"key": "review_cycle", "label": "دوره بازبینی", "type": "select", "options": [
            {"value": "monthly", "label": "ماهانه"},
            {"value": "quarterly", "label": "سه‌ماهه"},
            {"value": "semi_annual", "label": "شش‌ماهه"},
            {"value": "yearly", "label": "سالانه"},
        ]},
        {"key": "owner", "label": "مالک", "type": "lookup", "lookup_endpoint": "/api/v1/access/users/"},
    ],
    "search_fields": ["code", "name", "description"],
    "default_sort": "-created_at",
    "actions": {
        "row": [
            {"key": "view", "label": "مشاهده", "icon": "HiOutlineEye"},
            {"key": "edit", "label": "ویرایش", "icon": "HiOutlinePencilSquare", "permission": "ppm.portfolio.update"},
            {"key": "delete", "label": "حذف", "icon": "HiOutlineTrash", "permission": "ppm.portfolio.delete", "confirm": True},
        ],
        "bulk": [
            {"key": "export", "label": "خروجی", "icon": "HiOutlineArrowDownTray", "permission": "ppm.portfolio.list"},
        ],
    },
}


# ═══════════════════════════════════════════════════
# Program Table
# ═══════════════════════════════════════════════════

PROGRAM_TABLE = {
    "id": "ppm_program_table",
    "title": "برنامه‌ها",
    "endpoint": "/api/v1/ppm/programs/",
    "columns": [
        {"key": "code", "label": "کد", "sortable": True, "width": 100},
        {"key": "name", "label": "نام", "sortable": True, "width": 200},
        {"key": "portfolio_name", "label": "پرتفولیو", "width": 150},
        {
            "key": "status", "label": "وضعیت", "sortable": True, "width": 110,
            "badge_map": {
                "draft": {"label": "پیش‌نویس", "color": "gray"},
                "active": {"label": "فعال", "color": "green"},
                "on_hold": {"label": "متوقف", "color": "yellow"},
                "completed": {"label": "تکمیل‌شده", "color": "blue"},
                "closed": {"label": "بسته‌شده", "color": "red"},
                "cancelled": {"label": "لغوشده", "color": "purple"},
            },
        },
        {"key": "manager_name", "label": "مدیر برنامه", "width": 150},
        {"key": "budget", "label": "بودجه", "type": "currency", "width": 140},
        {"key": "progress", "label": "پیشرفت", "type": "progress", "width": 120},
        {
            "key": "risk_level", "label": "سطح ریسک", "sortable": True, "width": 100,
            "badge_map": {
                "low": {"label": "پایین", "color": "green"},
                "medium": {"label": "متوسط", "color": "yellow"},
                "high": {"label": "بالا", "color": "orange"},
                "critical": {"label": "بحرانی", "color": "red"},
            },
        },
        {"key": "start_date", "label": "شروع", "sortable": True, "type": "date_jalali", "width": 120},
        {"key": "end_date", "label": "پایان", "sortable": True, "type": "date_jalali", "width": 120},
        {"key": "created_at", "label": "تاریخ ایجاد", "sortable": True, "type": "date_jalali", "width": 130},
    ],
    "filters": [
        {"key": "status", "label": "وضعیت", "type": "select", "options": [
            {"value": "draft", "label": "پیش‌نویس"},
            {"value": "active", "label": "فعال"},
            {"value": "on_hold", "label": "متوقف"},
            {"value": "completed", "label": "تکمیل‌شده"},
            {"value": "closed", "label": "بسته‌شده"},
            {"value": "cancelled", "label": "لغوشده"},
        ]},
        {"key": "risk_level", "label": "سطح ریسک", "type": "select", "options": [
            {"value": "low", "label": "پایین"},
            {"value": "medium", "label": "متوسط"},
            {"value": "high", "label": "بالا"},
            {"value": "critical", "label": "بحرانی"},
        ]},
        {"key": "portfolio", "label": "پرتفولیو", "type": "lookup", "lookup_endpoint": "/api/v1/ppm/portfolios/"},
        {"key": "manager", "label": "مدیر برنامه", "type": "lookup", "lookup_endpoint": "/api/v1/access/users/"},
    ],
    "search_fields": ["code", "name", "description", "objectives"],
    "default_sort": "-created_at",
    "actions": {
        "row": [
            {"key": "view", "label": "مشاهده", "icon": "HiOutlineEye"},
            {"key": "edit", "label": "ویرایش", "icon": "HiOutlinePencilSquare", "permission": "ppm.program.update"},
            {"key": "delete", "label": "حذف", "icon": "HiOutlineTrash", "permission": "ppm.program.delete", "confirm": True},
        ],
        "bulk": [
            {"key": "export", "label": "خروجی", "icon": "HiOutlineArrowDownTray", "permission": "ppm.program.list"},
        ],
    },
}


# ═══════════════════════════════════════════════════
# Program-Project Table
# ═══════════════════════════════════════════════════

PROGRAM_PROJECT_TABLE = {
    "id": "ppm_program_project_table",
    "title": "پروژه‌های برنامه",
    "endpoint": "/api/v1/ppm/program-projects/",
    "columns": [
        {"key": "program", "label": "برنامه", "width": 200},
        {"key": "project_id", "label": "پروژه", "width": 200},
        {
            "key": "role", "label": "نقش", "width": 100,
            "badge_map": {
                "core": {"label": "اصلی", "color": "blue"},
                "supporting": {"label": "حمایتی", "color": "gray"},
            },
        },
        {"key": "priority", "label": "اولویت", "sortable": True, "width": 80},
        {"key": "notes", "label": "یادداشت", "width": 250},
        {"key": "created_at", "label": "تاریخ ایجاد", "sortable": True, "type": "date_jalali", "width": 130},
    ],
    "filters": [
        {"key": "role", "label": "نقش", "type": "select", "options": [
            {"value": "core", "label": "اصلی"},
            {"value": "supporting", "label": "حمایتی"},
        ]},
        {"key": "program", "label": "برنامه", "type": "lookup", "lookup_endpoint": "/api/v1/ppm/programs/"},
    ],
    "search_fields": ["notes"],
    "default_sort": "priority",
    "actions": {
        "row": [
            {"key": "edit", "label": "ویرایش", "icon": "HiOutlinePencilSquare", "permission": "ppm.program_project.update"},
            {"key": "delete", "label": "حذف", "icon": "HiOutlineTrash", "permission": "ppm.program_project.delete", "confirm": True},
        ],
    },
}


# ═══════════════════════════════════════════════════
# Business Case Table
# ═══════════════════════════════════════════════════

BUSINESS_CASE_TABLE = {
    "id": "ppm_business_case_table",
    "title": "کیس‌های تجاری",
    "endpoint": "/api/v1/ppm/business-cases/",
    "columns": [
        {"key": "title", "label": "عنوان", "sortable": True, "width": 250},
        {"key": "program_name", "label": "برنامه", "width": 150},
        {
            "key": "status", "label": "وضعیت", "sortable": True, "width": 110,
            "badge_map": {
                "draft": {"label": "پیش‌نویس", "color": "gray"},
                "submitted": {"label": "ارسال‌شده", "color": "blue"},
                "approved": {"label": "تأییدشده", "color": "green"},
                "rejected": {"label": "ردشده", "color": "red"},
            },
        },
        {"key": "sponsor_name", "label": "حامی", "width": 150},
        {"key": "prepared_by_name", "label": "تهیه‌کننده", "width": 150},
        {"key": "strategic_fit_score", "label": "امتیاز تناسب راهبردی", "sortable": True, "width": 130},
        {"key": "total_investment", "label": "سرمایه‌گذاری کل", "type": "currency", "sortable": True, "width": 150},
        {"key": "expected_revenue", "label": "درآمد پیش‌بینی", "type": "currency", "width": 140},
        {"key": "expected_savings", "label": "صرفه‌جویی پیش‌بینی", "type": "currency", "width": 140},
        {"key": "payback_period_months", "label": "دوره بازگشت (ماه)", "sortable": True, "width": 130},
        {"key": "created_at", "label": "تاریخ ایجاد", "sortable": True, "type": "date_jalali", "width": 130},
    ],
    "filters": [
        {"key": "status", "label": "وضعیت", "type": "select", "options": [
            {"value": "draft", "label": "پیش‌نویس"},
            {"value": "submitted", "label": "ارسال‌شده"},
            {"value": "approved", "label": "تأییدشده"},
            {"value": "rejected", "label": "ردشده"},
        ]},
        {"key": "program", "label": "برنامه", "type": "lookup", "lookup_endpoint": "/api/v1/ppm/programs/"},
        {"key": "sponsor", "label": "حامی", "type": "lookup", "lookup_endpoint": "/api/v1/access/users/"},
        {"key": "prepared_by", "label": "تهیه‌کننده", "type": "lookup", "lookup_endpoint": "/api/v1/access/users/"},
    ],
    "search_fields": ["title", "description", "assumptions"],
    "default_sort": "-created_at",
    "actions": {
        "row": [
            {"key": "view", "label": "مشاهده", "icon": "HiOutlineEye"},
            {"key": "edit", "label": "ویرایش", "icon": "HiOutlinePencilSquare", "permission": "ppm.business_case.update"},
            {"key": "evaluate", "label": "ارزیابی مالی", "icon": "HiOutlineCalculator", "handler": "detail:/api/v1/ppm/business-cases/{row.id}/evaluate/"},
            {"key": "delete", "label": "حذف", "icon": "HiOutlineTrash", "permission": "ppm.business_case.delete", "confirm": True},
        ],
        "bulk": [
            {"key": "export", "label": "خروجی", "icon": "HiOutlineArrowDownTray", "permission": "ppm.business_case.list"},
        ],
    },
}


# ═══════════════════════════════════════════════════
# CashFlow Projection Table
# ═══════════════════════════════════════════════════

CASH_FLOW_TABLE = {
    "id": "ppm_cash_flow_table",
    "title": "جریان‌های نقدی",
    "endpoint": "/api/v1/ppm/cash-flows/",
    "columns": [
        {"key": "business_case", "label": "کیس تجاری", "width": 200},
        {"key": "year", "label": "سال", "sortable": True, "width": 80},
        {"key": "investment", "label": "سرمایه‌گذاری", "type": "currency", "width": 140},
        {"key": "revenue", "label": "درآمد", "type": "currency", "width": 140},
        {"key": "savings", "label": "صرفه‌جویی", "type": "currency", "width": 140},
        {"key": "operational_cost", "label": "هزینه عملیاتی", "type": "currency", "width": 140},
        {"key": "net_cash_flow", "label": "جریان نقدی خالص", "type": "currency", "width": 150},
        {"key": "created_at", "label": "تاریخ ایجاد", "sortable": True, "type": "date_jalali", "width": 130},
    ],
    "filters": [
        {"key": "business_case", "label": "کیس تجاری", "type": "lookup", "lookup_endpoint": "/api/v1/ppm/business-cases/"},
        {"key": "year", "label": "سال", "type": "number"},
    ],
    "default_sort": "year",
    "actions": {
        "row": [
            {"key": "edit", "label": "ویرایش", "icon": "HiOutlinePencilSquare", "permission": "ppm.cash_flow.update"},
            {"key": "delete", "label": "حذف", "icon": "HiOutlineTrash", "permission": "ppm.cash_flow.delete", "confirm": True},
        ],
    },
}


# ═══════════════════════════════════════════════════
# Scoring Model Table
# ═══════════════════════════════════════════════════

SCORING_MODEL_TABLE = {
    "id": "ppm_scoring_model_table",
    "title": "مدل‌های امتیازدهی",
    "endpoint": "/api/v1/ppm/scoring-models/",
    "columns": [
        {"key": "name", "label": "نام", "sortable": True, "width": 250},
        {"key": "portfolio_name", "label": "پرتفولیو", "width": 150},
        {
            "key": "is_active", "label": "وضعیت", "sortable": True, "width": 100,
            "badge_map": {
                "true": {"label": "فعال", "color": "green"},
                "false": {"label": "غیرفعال", "color": "gray"},
            },
        },
        {"key": "criteria_count", "label": "تعداد معیارها", "width": 110},
        {"key": "description", "label": "توضیحات", "width": 250},
        {"key": "created_at", "label": "تاریخ ایجاد", "sortable": True, "type": "date_jalali", "width": 130},
    ],
    "filters": [
        {"key": "is_active", "label": "وضعیت", "type": "select", "options": [
            {"value": "true", "label": "فعال"},
            {"value": "false", "label": "غیرفعال"},
        ]},
        {"key": "portfolio", "label": "پرتفولیو", "type": "lookup", "lookup_endpoint": "/api/v1/ppm/portfolios/"},
    ],
    "search_fields": ["name", "description"],
    "default_sort": "-created_at",
    "actions": {
        "row": [
            {"key": "view", "label": "مشاهده", "icon": "HiOutlineEye"},
            {"key": "edit", "label": "ویرایش", "icon": "HiOutlinePencilSquare", "permission": "ppm.scoring_model.update"},
            {"key": "rank", "label": "رتبه‌بندی", "icon": "HiOutlineChartBar", "handler": "detail:/api/v1/ppm/scoring-models/{row.id}/rank-projects/"},
            {"key": "delete", "label": "حذف", "icon": "HiOutlineTrash", "permission": "ppm.scoring_model.delete", "confirm": True},
        ],
        "bulk": [
            {"key": "export", "label": "خروجی", "icon": "HiOutlineArrowDownTray", "permission": "ppm.scoring_model.list"},
        ],
    },
}


# ═══════════════════════════════════════════════════
# Scoring Criterion Table
# ═══════════════════════════════════════════════════

SCORING_CRITERION_TABLE = {
    "id": "ppm_scoring_criterion_table",
    "title": "معیارهای امتیازدهی",
    "endpoint": "/api/v1/ppm/scoring-criteria/",
    "columns": [
        {"key": "name", "label": "نام", "sortable": True, "width": 200},
        {"key": "scoring_model", "label": "مدل", "width": 150},
        {
            "key": "category", "label": "دسته‌بندی", "width": 110,
            "badge_map": {
                "strategic": {"label": "راهبردی", "color": "blue"},
                "financial": {"label": "مالی", "color": "green"},
                "risk": {"label": "ریسک", "color": "red"},
                "resource": {"label": "منابع", "color": "yellow"},
                "technical": {"label": "فنی", "color": "purple"},
                "organizational": {"label": "سازمانی", "color": "gray"},
            },
        },
        {"key": "weight", "label": "وزن", "sortable": True, "width": 80},
        {"key": "scale_min", "label": "حداقل", "width": 70},
        {"key": "scale_max", "label": "حداکثر", "width": 70},
        {"key": "order", "label": "ترتیب", "sortable": True, "width": 70},
        {"key": "created_at", "label": "تاریخ ایجاد", "sortable": True, "type": "date_jalali", "width": 130},
    ],
    "filters": [
        {"key": "category", "label": "دسته‌بندی", "type": "select", "options": [
            {"value": "strategic", "label": "راهبردی"},
            {"value": "financial", "label": "مالی"},
            {"value": "risk", "label": "ریسک"},
            {"value": "resource", "label": "منابع"},
            {"value": "technical", "label": "فنی"},
            {"value": "organizational", "label": "سازمانی"},
        ]},
        {"key": "scoring_model", "label": "مدل", "type": "lookup", "lookup_endpoint": "/api/v1/ppm/scoring-models/"},
    ],
    "search_fields": ["name", "description"],
    "default_sort": "order",
    "actions": {
        "row": [
            {"key": "edit", "label": "ویرایش", "icon": "HiOutlinePencilSquare", "permission": "ppm.scoring_criterion.update"},
            {"key": "delete", "label": "حذف", "icon": "HiOutlineTrash", "permission": "ppm.scoring_criterion.delete", "confirm": True},
        ],
    },
}


# ═══════════════════════════════════════════════════
# Project Score Table
# ═══════════════════════════════════════════════════

PROJECT_SCORE_TABLE = {
    "id": "ppm_project_score_table",
    "title": "امتیازات پروژه",
    "endpoint": "/api/v1/ppm/project-scores/",
    "columns": [
        {"key": "project_id", "label": "پروژه", "width": 200},
        {"key": "scoring_model", "label": "مدل", "width": 150},
        {"key": "criterion_name", "label": "معیار", "width": 200},
        {"key": "score", "label": "امتیاز", "sortable": True, "width": 80},
        {"key": "justification", "label": "توجیه", "width": 250},
        {"key": "scored_by_name", "label": "امتیازدهنده", "width": 150},
        {"key": "scored_at", "label": "تاریخ امتیاز", "sortable": True, "type": "date_jalali", "width": 130},
    ],
    "filters": [
        {"key": "scoring_model", "label": "مدل", "type": "lookup", "lookup_endpoint": "/api/v1/ppm/scoring-models/"},
        {"key": "criterion", "label": "معیار", "type": "lookup", "lookup_endpoint": "/api/v1/ppm/scoring-criteria/"},
        {"key": "scored_by", "label": "امتیازدهنده", "type": "lookup", "lookup_endpoint": "/api/v1/access/users/"},
    ],
    "search_fields": ["justification"],
    "default_sort": "-created_at",
    "actions": {
        "row": [
            {"key": "edit", "label": "ویرایش", "icon": "HiOutlinePencilSquare", "permission": "ppm.project_score.update"},
            {"key": "delete", "label": "حذف", "icon": "HiOutlineTrash", "permission": "ppm.project_score.delete", "confirm": True},
        ],
        "bulk": [
            {"key": "export", "label": "خروجی", "icon": "HiOutlineArrowDownTray", "permission": "ppm.project_score.list"},
        ],
    },
}


# ═══════════════════════════════════════════════════
# Benefit Plan Table
# ═══════════════════════════════════════════════════

BENEFIT_PLAN_TABLE = {
    "id": "ppm_benefit_plan_table",
    "title": "برنامه‌های تحقق منافع",
    "endpoint": "/api/v1/ppm/benefit-plans/",
    "columns": [
        {"key": "name", "label": "نام", "sortable": True, "width": 250},
        {"key": "program_name", "label": "برنامه", "width": 200},
        {"key": "portfolio_name", "label": "پرتفولیو", "width": 200},
        {"key": "is_active", "label": "فعال", "type": "boolean", "width": 80},
        {"key": "benefits_count", "label": "تعداد منافع", "width": 100},
        {"key": "created_at", "label": "تاریخ ایجاد", "sortable": True, "type": "date_jalali", "width": 130},
    ],
    "filters": [
        {"key": "program", "label": "برنامه", "type": "lookup", "lookup_endpoint": "/api/v1/ppm/programs/"},
        {"key": "portfolio", "label": "پرتفولیو", "type": "lookup", "lookup_endpoint": "/api/v1/ppm/portfolios/"},
        {"key": "is_active", "label": "فعال", "type": "boolean"},
    ],
    "search_fields": ["name", "description"],
    "default_sort": "-created_at",
    "actions": {
        "row": [
            {"key": "detail", "label": "مشاهده", "icon": "HiOutlineEye", "handler": "detail:/api/v1/ppm/benefit-plans/{row.id}/"},
            {"key": "edit", "label": "ویرایش", "icon": "HiOutlinePencilSquare", "permission": "ppm.benefit_plan.update"},
            {"key": "delete", "label": "حذف", "icon": "HiOutlineTrash", "permission": "ppm.benefit_plan.delete", "confirm": True},
        ],
        "bulk": [
            {"key": "export", "label": "خروجی", "icon": "HiOutlineArrowDownTray", "permission": "ppm.benefit_plan.list"},
        ],
    },
}


# ═══════════════════════════════════════════════════
# Benefit Table
# ═══════════════════════════════════════════════════

BENEFIT_TABLE = {
    "id": "ppm_benefit_table",
    "title": "منافع",
    "endpoint": "/api/v1/ppm/benefits/",
    "columns": [
        {"key": "title", "label": "عنوان", "sortable": True, "width": 250},
        {"key": "benefit_type", "label": "نوع", "width": 100},
        {"key": "category", "label": "دسته‌بندی", "width": 130},
        {"key": "status", "label": "وضعیت", "sortable": True, "width": 120},
        {"key": "target_value", "label": "مقدار هدف", "sortable": True, "type": "number", "width": 130},
        {"key": "actual_value", "label": "مقدار واقعی", "sortable": True, "type": "number", "width": 130},
        {"key": "realization_percentage", "label": "درصد تحقق", "type": "number", "width": 100},
        {"key": "owner_name", "label": "مسئول", "width": 150},
        {"key": "target_date", "label": "تاریخ هدف", "sortable": True, "type": "date_jalali", "width": 130},
        {"key": "created_at", "label": "تاریخ ایجاد", "sortable": True, "type": "date_jalali", "width": 130},
    ],
    "filters": [
        {"key": "benefit_plan", "label": "برنامه تحقق", "type": "lookup", "lookup_endpoint": "/api/v1/ppm/benefit-plans/"},
        {"key": "benefit_type", "label": "نوع", "type": "select", "options": [
            {"value": "financial", "label": "مالی"},
            {"value": "non_financial", "label": "غیرمالی"},
        ]},
        {"key": "status", "label": "وضعیت", "type": "select", "options": [
            {"value": "identified", "label": "شناسایی‌شده"},
            {"value": "planned", "label": "برنامه‌ریزی‌شده"},
            {"value": "realized", "label": "تحقق‌یافته"},
            {"value": "failed", "label": "ناموفق"},
        ]},
        {"key": "frequency", "label": "فرکانس", "type": "select", "options": [
            {"value": "weekly", "label": "هفتگی"},
            {"value": "monthly", "label": "ماهانه"},
            {"value": "quarterly", "label": "سه‌ماهه"},
            {"value": "yearly", "label": "سالانه"},
        ]},
        {"key": "owner", "label": "مسئول", "type": "lookup", "lookup_endpoint": "/api/v1/access/users/"},
    ],
    "search_fields": ["title", "description", "category"],
    "default_sort": "-created_at",
    "actions": {
        "row": [
            {"key": "detail", "label": "مشاهده", "icon": "HiOutlineEye", "handler": "detail:/api/v1/ppm/benefits/{row.id}/"},
            {"key": "edit", "label": "ویرایش", "icon": "HiOutlinePencilSquare", "permission": "ppm.benefit.update"},
            {"key": "delete", "label": "حذف", "icon": "HiOutlineTrash", "permission": "ppm.benefit.delete", "confirm": True},
        ],
        "bulk": [
            {"key": "export", "label": "خروجی", "icon": "HiOutlineArrowDownTray", "permission": "ppm.benefit.list"},
        ],
    },
}


# ═══════════════════════════════════════════════════
# Benefit Measurement Table
# ═══════════════════════════════════════════════════

BENEFIT_MEASUREMENT_TABLE = {
    "id": "ppm_benefit_measurement_table",
    "title": "اندازه‌گیری‌های منفعت",
    "endpoint": "/api/v1/ppm/benefit-measurements/",
    "columns": [
        {"key": "benefit", "label": "منفعت", "width": 250},
        {"key": "measurement_date", "label": "تاریخ اندازه‌گیری", "sortable": True, "type": "date_jalali", "width": 150},
        {"key": "value", "label": "مقدار", "sortable": True, "type": "number", "width": 130},
        {"key": "notes", "label": "یادداشت", "width": 300},
        {"key": "measured_by_name", "label": "اندازه‌گیری‌کننده", "width": 150},
        {"key": "created_at", "label": "تاریخ ایجاد", "sortable": True, "type": "date_jalali", "width": 130},
    ],
    "filters": [
        {"key": "benefit", "label": "منفعت", "type": "lookup", "lookup_endpoint": "/api/v1/ppm/benefits/"},
        {"key": "measured_by", "label": "اندازه‌گیری‌کننده", "type": "lookup", "lookup_endpoint": "/api/v1/access/users/"},
    ],
    "search_fields": ["notes"],
    "default_sort": "-measurement_date",
    "actions": {
        "row": [
            {"key": "edit", "label": "ویرایش", "icon": "HiOutlinePencilSquare", "permission": "ppm.benefit_measurement.update"},
            {"key": "delete", "label": "حذف", "icon": "HiOutlineTrash", "permission": "ppm.benefit_measurement.delete", "confirm": True},
        ],
        "bulk": [
            {"key": "export", "label": "خروجی", "icon": "HiOutlineArrowDownTray", "permission": "ppm.benefit_measurement.list"},
        ],
    },
}


# ═══════════════════════════════════════════════════
# Capacity Plan Table
# ═══════════════════════════════════════════════════

CAPACITY_PLAN_TABLE = {
    "id": "ppm_capacity_plan_table",
    "title": "طرح‌های ظرفیت",
    "endpoint": "/api/v1/ppm/capacity-plans/",
    "columns": [
        {"key": "name", "label": "نام", "sortable": True, "width": 250},
        {"key": "description", "label": "توضیحات", "width": 300},
        {"key": "portfolio_id", "label": "پرتفولیو", "width": 200},
        {"key": "period_start", "label": "شروع دوره", "sortable": True, "type": "date_jalali", "width": 130},
        {"key": "period_end", "label": "پایان دوره", "sortable": True, "type": "date_jalali", "width": 130},
        {"key": "is_active", "label": "فعال", "sortable": True, "type": "boolean", "width": 80},
        {"key": "demands_count", "label": "تعداد تقاضا", "type": "number", "width": 100},
        {"key": "supplies_count", "label": "تعداد عرضه", "type": "number", "width": 100},
        {"key": "created_at", "label": "تاریخ ایجاد", "sortable": True, "type": "date_jalali", "width": 130},
    ],
    "filters": [
        {"key": "is_active", "label": "وضعیت فعال", "type": "boolean"},
        {"key": "portfolio_id", "label": "پرتفولیو", "type": "lookup", "lookup_endpoint": "/api/v1/ppm/portfolios/"},
    ],
    "search_fields": ["name", "description"],
    "default_sort": "-created_at",
    "actions": {
        "row": [
            {"key": "detail", "label": "جزئیات", "icon": "HiOutlineEye", "handler": "detail:/api/v1/ppm/capacity-plans/{row.id}/"},
            {"key": "edit", "label": "ویرایش", "icon": "HiOutlinePencilSquare", "permission": "ppm.capacity_plan.update"},
            {"key": "analyze", "label": "تحلیل ظرفیت", "icon": "HiOutlineChartBar", "handler": "api:GET:/api/v1/ppm/capacity-plans/{row.id}/analyze/"},
            {"key": "delete", "label": "حذف", "icon": "HiOutlineTrash", "permission": "ppm.capacity_plan.delete", "confirm": True},
        ],
        "bulk": [
            {"key": "export", "label": "خروجی", "icon": "HiOutlineArrowDownTray", "permission": "ppm.capacity_plan.list"},
        ],
    },
}


# ═══════════════════════════════════════════════════
# Resource Demand Table
# ═══════════════════════════════════════════════════

RESOURCE_DEMAND_TABLE = {
    "id": "ppm_resource_demand_table",
    "title": "تقاضای منابع",
    "endpoint": "/api/v1/ppm/resource-demands/",
    "columns": [
        {"key": "capacity_plan", "label": "طرح ظرفیت", "width": 200},
        {"key": "resource_type", "label": "نوع منبع", "sortable": True, "width": 150},
        {"key": "project_id", "label": "پروژه", "width": 200},
        {"key": "demand_hours", "label": "ساعت تقاضا", "sortable": True, "type": "number", "width": 120},
        {"key": "period", "label": "دوره", "sortable": True, "width": 130},
        {"key": "notes", "label": "یادداشت", "width": 250},
        {"key": "created_at", "label": "تاریخ ایجاد", "sortable": True, "type": "date_jalali", "width": 130},
    ],
    "filters": [
        {"key": "capacity_plan", "label": "طرح ظرفیت", "type": "lookup", "lookup_endpoint": "/api/v1/ppm/capacity-plans/"},
        {"key": "resource_type", "label": "نوع منبع", "type": "text"},
        {"key": "project_id", "label": "پروژه", "type": "text"},
    ],
    "search_fields": ["resource_type", "notes"],
    "default_sort": "period",
    "actions": {
        "row": [
            {"key": "edit", "label": "ویرایش", "icon": "HiOutlinePencilSquare", "permission": "ppm.resource_demand.update"},
            {"key": "delete", "label": "حذف", "icon": "HiOutlineTrash", "permission": "ppm.resource_demand.delete", "confirm": True},
        ],
        "bulk": [
            {"key": "export", "label": "خروجی", "icon": "HiOutlineArrowDownTray", "permission": "ppm.resource_demand.list"},
        ],
    },
}


# ═══════════════════════════════════════════════════
# Resource Supply Table
# ═══════════════════════════════════════════════════

RESOURCE_SUPPLY_TABLE = {
    "id": "ppm_resource_supply_table",
    "title": "عرضه منابع",
    "endpoint": "/api/v1/ppm/resource-supplies/",
    "columns": [
        {"key": "capacity_plan", "label": "طرح ظرفیت", "width": 200},
        {"key": "resource_type", "label": "نوع منبع", "sortable": True, "width": 150},
        {"key": "available_hours", "label": "ساعت موجود", "sortable": True, "type": "number", "width": 120},
        {"key": "period", "label": "دوره", "sortable": True, "width": 130},
        {"key": "notes", "label": "یادداشت", "width": 250},
        {"key": "created_at", "label": "تاریخ ایجاد", "sortable": True, "type": "date_jalali", "width": 130},
    ],
    "filters": [
        {"key": "capacity_plan", "label": "طرح ظرفیت", "type": "lookup", "lookup_endpoint": "/api/v1/ppm/capacity-plans/"},
        {"key": "resource_type", "label": "نوع منبع", "type": "text"},
    ],
    "search_fields": ["resource_type", "notes"],
    "default_sort": "period",
    "actions": {
        "row": [
            {"key": "edit", "label": "ویرایش", "icon": "HiOutlinePencilSquare", "permission": "ppm.resource_supply.update"},
            {"key": "delete", "label": "حذف", "icon": "HiOutlineTrash", "permission": "ppm.resource_supply.delete", "confirm": True},
        ],
        "bulk": [
            {"key": "export", "label": "خروجی", "icon": "HiOutlineArrowDownTray", "permission": "ppm.resource_supply.list"},
        ],
    },
}


# ═══════════════════════════════════════════════════
# Cross-Project Dependency Table
# ═══════════════════════════════════════════════════

CROSS_PROJECT_DEPENDENCY_TABLE = {
    "id": "ppm_cross_project_dependency_table",
    "title": "وابستگی‌های بین پروژه‌ای",
    "endpoint": "/api/v1/ppm/dependencies/",
    "columns": [
        {"key": "predecessor_project_id", "label": "پروژه پیش‌نیاز", "width": 200},
        {"key": "successor_project_id", "label": "پروژه وابسته", "width": 200},
        {"key": "dependency_type", "label": "نوع وابستگی", "sortable": True, "width": 120},
        {"key": "lag_days", "label": "تأخیر (روز)", "sortable": True, "type": "number", "width": 100},
        {"key": "status", "label": "وضعیت", "sortable": True, "width": 100},
        {"key": "impact_description", "label": "توضیح تأثیر", "width": 300},
        {"key": "created_at", "label": "تاریخ ایجاد", "sortable": True, "type": "date_jalali", "width": 130},
    ],
    "filters": [
        {"key": "dependency_type", "label": "نوع وابستگی", "type": "select", "options": [
            {"value": "FS", "label": "پایان-به-شروع"},
            {"value": "SS", "label": "شروع-به-شروع"},
            {"value": "FF", "label": "پایان-به-پایان"},
            {"value": "SF", "label": "شروع-به-پایان"},
        ]},
        {"key": "status", "label": "وضعیت", "type": "select", "options": [
            {"value": "active", "label": "فعال"},
            {"value": "resolved", "label": "حل‌شده"},
        ]},
        {"key": "predecessor_project_id", "label": "پروژه پیش‌نیاز", "type": "text"},
        {"key": "successor_project_id", "label": "پروژه وابسته", "type": "text"},
    ],
    "search_fields": ["impact_description"],
    "default_sort": "-created_at",
    "actions": {
        "row": [
            {"key": "edit", "label": "ویرایش", "icon": "HiOutlinePencilSquare", "permission": "ppm.cross_project_dependency.update"},
            {"key": "delete", "label": "حذف", "icon": "HiOutlineTrash", "permission": "ppm.cross_project_dependency.delete", "confirm": True},
        ],
        "bulk": [
            {"key": "export", "label": "خروجی", "icon": "HiOutlineArrowDownTray", "permission": "ppm.cross_project_dependency.list"},
        ],
        "global": [
            {"key": "circular_check", "label": "بررسی وابستگی حلقوی", "icon": "HiOutlineArrowPath", "handler": "api:GET:/api/v1/ppm/dependencies/circular-check/"},
            {"key": "critical_chain", "label": "زنجیره بحرانی", "icon": "HiOutlineLink", "handler": "api:GET:/api/v1/ppm/dependencies/critical-chain/"},
        ],
    },
}
