"""
PM Module — Table Schemas.

تعریف schema جداول ماژول مدیریت پروژه.
"""

# ═══════════════════════════════════════════════════
# Project Table
# ═══════════════════════════════════════════════════

PROJECT_TABLE = {
    "id": "pm_project_table",
    "title": "لیست پروژه‌ها",
    "endpoint": "/api/v1/pm/projects/",
    "columns": [
        {"key": "code", "title": "کد", "sortable": True, "width": 100},
        {"key": "title", "title": "عنوان", "sortable": True, "width": 250},
        {
            "key": "project_type", "title": "نوع", "sortable": True, "width": 100,
            "type": "badge",
            "badge_map": {
                "portfolio": {"label": "پورتفولیو", "color": "purple"},
                "program": {"label": "برنامه", "color": "indigo"},
                "project": {"label": "پروژه", "color": "blue"},
                "sub_project": {"label": "زیرپروژه", "color": "cyan"},
            },
        },
        {
            "key": "status", "title": "وضعیت", "sortable": True, "width": 120,
            "type": "badge",
            "badge_map": {
                "draft": {"label": "پیش‌نویس", "color": "gray"},
                "planning": {"label": "برنامه‌ریزی", "color": "yellow"},
                "active": {"label": "فعال", "color": "green"},
                "on_hold": {"label": "متوقف", "color": "orange"},
                "completed": {"label": "تکمیل‌شده", "color": "blue"},
                "cancelled": {"label": "لغوشده", "color": "red"},
                "archived": {"label": "آرشیو", "color": "gray"},
            },
        },
        {
            "key": "priority", "title": "اولویت", "sortable": True, "width": 100,
            "type": "badge",
            "badge_map": {
                "critical": {"label": "بحرانی", "color": "red"},
                "high": {"label": "بالا", "color": "orange"},
                "medium": {"label": "متوسط", "color": "yellow"},
                "low": {"label": "پایین", "color": "green"},
            },
        },
        {"key": "progress", "title": "پیشرفت (%)", "sortable": True, "width": 100, "type": "progress"},
        {"key": "manager_name", "title": "مدیر پروژه", "width": 150},
        {"key": "planned_start", "title": "شروع برنامه‌ای", "sortable": True, "width": 120, "type": "date_jalali"},
        {"key": "planned_end", "title": "پایان برنامه‌ای", "sortable": True, "width": 120, "type": "date_jalali"},
        {"key": "total_budget", "title": "بودجه", "sortable": True, "width": 120, "type": "currency"},
    ],
    "filters": [
        {
            "key": "status", "label": "وضعیت", "type": "select",
            "options": [
                {"value": "draft", "label": "پیش‌نویس"},
                {"value": "planning", "label": "برنامه‌ریزی"},
                {"value": "active", "label": "فعال"},
                {"value": "on_hold", "label": "متوقف"},
                {"value": "completed", "label": "تکمیل‌شده"},
                {"value": "cancelled", "label": "لغوشده"},
            ],
        },
        {
            "key": "priority", "label": "اولویت", "type": "select",
            "options": [
                {"value": "critical", "label": "بحرانی"},
                {"value": "high", "label": "بالا"},
                {"value": "medium", "label": "متوسط"},
                {"value": "low", "label": "پایین"},
            ],
        },
        {
            "key": "project_type", "label": "نوع پروژه", "type": "select",
            "options": [
                {"value": "portfolio", "label": "پورتفولیو"},
                {"value": "program", "label": "برنامه"},
                {"value": "project", "label": "پروژه"},
                {"value": "sub_project", "label": "زیرپروژه"},
            ],
        },
        {"key": "manager", "label": "مدیر پروژه", "type": "lookup", "lookup_endpoint": "/api/v1/auth/users/"},
        {"key": "company", "label": "شرکت", "type": "lookup", "lookup_endpoint": "/api/v1/organization/companies/"},
    ],
    "search_fields": ["code", "title", "description"],
    "default_sort": "-created_at",
    "actions": {
        "row": [
            {"key": "view", "label": "مشاهده", "icon": "HiOutlineEye"},
            {"key": "edit", "label": "ویرایش", "icon": "HiOutlinePencilSquare", "permission": "pm.project.update"},
            {"key": "gantt", "label": "نمودار گانت", "icon": "HiOutlineBars3BottomLeft"},
            {"key": "delete", "label": "حذف", "icon": "HiOutlineTrash", "permission": "pm.project.manage", "confirm": True},
        ],
        "bulk": [
            {"key": "export", "label": "خروجی", "icon": "HiOutlineArrowDownTray"},
        ],
    },
}


# ═══════════════════════════════════════════════════
# Task Table
# ═══════════════════════════════════════════════════

TASK_TABLE = {
    "id": "pm_task_table",
    "title": "لیست تسک‌ها",
    "endpoint": "/api/v1/pm/tasks/",
    "columns": [
        {"key": "code", "title": "کد WBS", "sortable": True, "width": 120},
        {"key": "title", "title": "عنوان", "sortable": True, "width": 250},
        {
            "key": "task_type", "title": "نوع", "width": 100,
            "type": "badge",
            "badge_map": {
                "task": {"label": "تسک", "color": "blue"},
                "milestone": {"label": "مایلستون", "color": "purple"},
                "summary": {"label": "خلاصه", "color": "indigo"},
            },
        },
        {
            "key": "status", "title": "وضعیت", "sortable": True, "width": 120,
            "type": "badge",
            "badge_map": {
                "not_started": {"label": "شروع نشده", "color": "gray"},
                "in_progress": {"label": "در حال انجام", "color": "blue"},
                "completed": {"label": "تکمیل‌شده", "color": "green"},
                "on_hold": {"label": "متوقف", "color": "orange"},
                "cancelled": {"label": "لغوشده", "color": "red"},
            },
        },
        {"key": "progress", "title": "پیشرفت (%)", "sortable": True, "width": 100, "type": "progress"},
        {"key": "assignee_name", "title": "مسئول", "width": 150},
        {"key": "planned_start", "title": "شروع", "sortable": True, "width": 110, "type": "date_jalali"},
        {"key": "planned_end", "title": "پایان", "sortable": True, "width": 110, "type": "date_jalali"},
        {"key": "duration_days", "title": "مدت (روز)", "sortable": True, "width": 90},
        {"key": "is_critical", "title": "بحرانی", "width": 80, "type": "boolean"},
    ],
    "filters": [
        {"key": "project", "label": "پروژه", "type": "lookup", "lookup_endpoint": "/api/v1/pm/projects/"},
        {
            "key": "status", "label": "وضعیت", "type": "select",
            "options": [
                {"value": "not_started", "label": "شروع نشده"},
                {"value": "in_progress", "label": "در حال انجام"},
                {"value": "completed", "label": "تکمیل‌شده"},
                {"value": "on_hold", "label": "متوقف"},
            ],
        },
        {
            "key": "task_type", "label": "نوع", "type": "select",
            "options": [
                {"value": "task", "label": "تسک"},
                {"value": "milestone", "label": "مایلستون"},
                {"value": "summary", "label": "خلاصه"},
            ],
        },
        {"key": "assignee", "label": "مسئول", "type": "lookup", "lookup_endpoint": "/api/v1/auth/users/"},
        {"key": "is_critical", "label": "فقط بحرانی", "type": "select", "options": [{"value": "true", "label": "بله"}]},
    ],
    "search_fields": ["code", "title", "description"],
    "default_sort": "sort_order",
    "actions": {
        "row": [
            {"key": "view", "label": "مشاهده", "icon": "HiOutlineEye"},
            {"key": "edit", "label": "ویرایش", "icon": "HiOutlinePencilSquare", "permission": "pm.task.update"},
            {"key": "delete", "label": "حذف", "icon": "HiOutlineTrash", "permission": "pm.task.manage", "confirm": True},
        ],
    },
}


# ═══════════════════════════════════════════════════
# Resource Table
# ═══════════════════════════════════════════════════

RESOURCE_TABLE = {
    "id": "pm_resource_table",
    "title": "لیست منابع",
    "endpoint": "/api/v1/pm/resources/",
    "columns": [
        {"key": "code", "title": "کد", "sortable": True, "width": 100},
        {"key": "name", "title": "نام", "sortable": True, "width": 200},
        {
            "key": "resource_type", "title": "نوع", "width": 120,
            "type": "badge",
            "badge_map": {
                "human": {"label": "انسانی", "color": "blue"},
                "equipment": {"label": "تجهیزات", "color": "orange"},
                "material": {"label": "مواد", "color": "green"},
            },
        },
        {"key": "email", "title": "ایمیل", "width": 180},
        {"key": "standard_rate", "title": "نرخ استاندارد", "width": 120, "type": "currency"},
        {"key": "max_units", "title": "ظرفیت (%)", "width": 100},
        {"key": "is_active", "title": "فعال", "width": 80, "type": "boolean"},
    ],
    "filters": [
        {
            "key": "resource_type", "label": "نوع منبع", "type": "select",
            "options": [
                {"value": "human", "label": "انسانی"},
                {"value": "equipment", "label": "تجهیزات"},
                {"value": "material", "label": "مواد"},
            ],
        },
        {"key": "company", "label": "شرکت", "type": "lookup", "lookup_endpoint": "/api/v1/organization/companies/"},
        {"key": "is_active", "label": "وضعیت", "type": "select", "options": [{"value": "true", "label": "فعال"}, {"value": "false", "label": "غیرفعال"}]},
    ],
    "search_fields": ["name", "code", "email"],
    "default_sort": "name",
    "actions": {
        "row": [
            {"key": "view", "label": "مشاهده", "icon": "HiOutlineEye"},
            {"key": "edit", "label": "ویرایش", "icon": "HiOutlinePencilSquare", "permission": "pm.resource.update"},
            {"key": "delete", "label": "حذف", "icon": "HiOutlineTrash", "permission": "pm.resource.manage", "confirm": True},
        ],
    },
}


# ═══════════════════════════════════════════════════
# Risk Table
# ═══════════════════════════════════════════════════

RISK_TABLE = {
    "id": "pm_risk_table",
    "title": "لیست ریسک‌ها",
    "endpoint": "/api/v1/pm/risks/",
    "columns": [
        {"key": "code", "title": "کد", "sortable": True, "width": 100},
        {"key": "title", "title": "عنوان", "sortable": True, "width": 250},
        {
            "key": "probability", "title": "احتمال", "width": 100,
            "type": "badge",
            "badge_map": {
                "very_low": {"label": "بسیار کم", "color": "green"},
                "low": {"label": "کم", "color": "cyan"},
                "medium": {"label": "متوسط", "color": "yellow"},
                "high": {"label": "بالا", "color": "orange"},
                "very_high": {"label": "بسیار بالا", "color": "red"},
            },
        },
        {
            "key": "impact", "title": "تأثیر", "width": 100,
            "type": "badge",
            "badge_map": {
                "very_low": {"label": "بسیار کم", "color": "green"},
                "low": {"label": "کم", "color": "cyan"},
                "medium": {"label": "متوسط", "color": "yellow"},
                "high": {"label": "بالا", "color": "orange"},
                "very_high": {"label": "بسیار بالا", "color": "red"},
            },
        },
        {"key": "risk_score", "title": "امتیاز ریسک", "sortable": True, "width": 100},
        {
            "key": "status", "title": "وضعیت", "width": 120,
            "type": "badge",
            "badge_map": {
                "identified": {"label": "شناسایی‌شده", "color": "gray"},
                "analyzing": {"label": "در حال تحلیل", "color": "blue"},
                "planned": {"label": "برنامه‌ریزی‌شده", "color": "indigo"},
                "monitoring": {"label": "پایش", "color": "yellow"},
                "occurred": {"label": "رخ داده", "color": "red"},
                "closed": {"label": "بسته‌شده", "color": "green"},
            },
        },
        {"key": "owner_name", "title": "مالک", "width": 150},
    ],
    "filters": [
        {"key": "project", "label": "پروژه", "type": "lookup", "lookup_endpoint": "/api/v1/pm/projects/"},
        {
            "key": "status", "label": "وضعیت", "type": "select",
            "options": [
                {"value": "identified", "label": "شناسایی‌شده"},
                {"value": "analyzing", "label": "در حال تحلیل"},
                {"value": "planned", "label": "برنامه‌ریزی‌شده"},
                {"value": "monitoring", "label": "پایش"},
                {"value": "occurred", "label": "رخ داده"},
                {"value": "closed", "label": "بسته‌شده"},
            ],
        },
        {
            "key": "probability", "label": "احتمال", "type": "select",
            "options": [
                {"value": "very_low", "label": "بسیار کم"},
                {"value": "low", "label": "کم"},
                {"value": "medium", "label": "متوسط"},
                {"value": "high", "label": "بالا"},
                {"value": "very_high", "label": "بسیار بالا"},
            ],
        },
    ],
    "search_fields": ["code", "title", "description"],
    "default_sort": "-created_at",
    "actions": {
        "row": [
            {"key": "view", "label": "مشاهده", "icon": "HiOutlineEye"},
            {"key": "edit", "label": "ویرایش", "icon": "HiOutlinePencilSquare", "permission": "pm.risk.update"},
            {"key": "delete", "label": "حذف", "icon": "HiOutlineTrash", "permission": "pm.risk.manage", "confirm": True},
        ],
    },
}


# ═══════════════════════════════════════════════════
# Budget Table
# ═══════════════════════════════════════════════════

BUDGET_TABLE = {
    "id": "pm_budget_table",
    "title": "بودجه",
    "endpoint": "/api/v1/pm/budgets/",
    "columns": [
        {"key": "name", "title": "عنوان", "sortable": True, "width": 200},
        {"key": "project_title", "title": "پروژه", "width": 200},
        {"key": "original_budget", "title": "بودجه اولیه", "width": 130, "type": "currency"},
        {"key": "revised_budget", "title": "بودجه بازنگری", "width": 130, "type": "currency"},
        {"key": "committed_cost", "title": "هزینه تعهدشده", "width": 130, "type": "currency"},
        {"key": "actual_cost", "title": "هزینه واقعی", "width": 130, "type": "currency"},
        {"key": "variance", "title": "انحراف", "width": 130, "type": "currency"},
        {"key": "is_active", "title": "فعال", "width": 80, "type": "boolean"},
    ],
    "filters": [
        {"key": "project", "label": "پروژه", "type": "lookup", "lookup_endpoint": "/api/v1/pm/projects/"},
        {"key": "is_active", "label": "وضعیت", "type": "select", "options": [{"value": "true", "label": "فعال"}]},
    ],
    "search_fields": ["name"],
    "default_sort": "-created_at",
    "actions": {
        "row": [
            {"key": "edit", "label": "ویرایش", "icon": "HiOutlinePencilSquare", "permission": "pm.cost.update"},
            {"key": "delete", "label": "حذف", "icon": "HiOutlineTrash", "permission": "pm.cost.manage", "confirm": True},
        ],
    },
}


# ═══════════════════════════════════════════════════
# Change Request Table
# ═══════════════════════════════════════════════════

CHANGE_REQUEST_TABLE = {
    "id": "pm_change_request_table",
    "title": "درخواست‌های تغییر",
    "endpoint": "/api/v1/pm/change-requests/",
    "columns": [
        {"key": "code", "title": "کد", "sortable": True, "width": 100},
        {"key": "title", "title": "عنوان", "sortable": True, "width": 250},
        {
            "key": "priority", "title": "اولویت", "width": 100,
            "type": "badge",
            "badge_map": {
                "critical": {"label": "بحرانی", "color": "red"},
                "high": {"label": "بالا", "color": "orange"},
                "medium": {"label": "متوسط", "color": "yellow"},
                "low": {"label": "پایین", "color": "green"},
            },
        },
        {
            "key": "status", "title": "وضعیت", "width": 120,
            "type": "badge",
            "badge_map": {
                "draft": {"label": "پیش‌نویس", "color": "gray"},
                "submitted": {"label": "ارسال‌شده", "color": "blue"},
                "under_review": {"label": "در حال بررسی", "color": "yellow"},
                "approved": {"label": "تأییدشده", "color": "green"},
                "rejected": {"label": "ردشده", "color": "red"},
                "implemented": {"label": "اجراشده", "color": "indigo"},
            },
        },
        {"key": "requester_name", "title": "درخواست‌کننده", "width": 150},
        {"key": "created_at", "title": "تاریخ ایجاد", "width": 120, "type": "date_jalali"},
    ],
    "filters": [
        {"key": "project", "label": "پروژه", "type": "lookup", "lookup_endpoint": "/api/v1/pm/projects/"},
        {
            "key": "status", "label": "وضعیت", "type": "select",
            "options": [
                {"value": "draft", "label": "پیش‌نویس"},
                {"value": "submitted", "label": "ارسال‌شده"},
                {"value": "under_review", "label": "در حال بررسی"},
                {"value": "approved", "label": "تأییدشده"},
                {"value": "rejected", "label": "ردشده"},
            ],
        },
    ],
    "search_fields": ["code", "title"],
    "default_sort": "-created_at",
    "actions": {
        "row": [
            {"key": "view", "label": "مشاهده", "icon": "HiOutlineEye"},
            {"key": "edit", "label": "ویرایش", "icon": "HiOutlinePencilSquare", "permission": "pm.project.update"},
        ],
    },
}


# ═══════════════════════════════════════════════════
# Timesheet Table
# ═══════════════════════════════════════════════════

TIMESHEET_TABLE = {
    "id": "pm_timesheet_table",
    "title": "تایم‌شیت",
    "endpoint": "/api/v1/pm/timesheets/",
    "columns": [
        {"key": "user_name", "title": "کاربر", "width": 150},
        {"key": "project_title", "title": "پروژه", "width": 180},
        {"key": "task_title", "title": "تسک", "width": 180},
        {"key": "work_date", "title": "تاریخ", "sortable": True, "width": 110, "type": "date_jalali"},
        {"key": "regular_hours", "title": "ساعت عادی", "width": 100},
        {"key": "overtime_hours", "title": "اضافه‌کاری", "width": 100},
        {"key": "total_hours", "title": "جمع", "width": 80},
        {
            "key": "status", "title": "وضعیت", "width": 110,
            "type": "badge",
            "badge_map": {
                "draft": {"label": "پیش‌نویس", "color": "gray"},
                "submitted": {"label": "ارسال‌شده", "color": "blue"},
                "approved": {"label": "تأیید‌شده", "color": "green"},
                "rejected": {"label": "ردشده", "color": "red"},
            },
        },
    ],
    "filters": [
        {"key": "project", "label": "پروژه", "type": "lookup", "lookup_endpoint": "/api/v1/pm/projects/"},
        {"key": "user", "label": "کاربر", "type": "lookup", "lookup_endpoint": "/api/v1/auth/users/"},
        {"key": "status", "label": "وضعیت", "type": "select", "options": [
            {"value": "draft", "label": "پیش‌نویس"},
            {"value": "submitted", "label": "ارسال‌شده"},
            {"value": "approved", "label": "تأیید‌شده"},
            {"value": "rejected", "label": "ردشده"},
        ]},
    ],
    "search_fields": [],
    "default_sort": "-work_date",
    "actions": {
        "row": [
            {"key": "edit", "label": "ویرایش", "icon": "HiOutlinePencilSquare"},
            {"key": "approve", "label": "تأیید", "icon": "HiOutlineCheck", "permission": "pm.task.approve"},
        ],
    },
}


# ═══════════════════════════════════════════════════
# Issue Table
# ═══════════════════════════════════════════════════

ISSUE_TABLE = {
    "id": "pm_issue_table",
    "title": "لیست مسائل",
    "endpoint": "/api/v1/pm/issues/",
    "columns": [
        {"key": "code", "title": "کد", "sortable": True, "width": 100},
        {"key": "title", "title": "عنوان", "sortable": True, "width": 250},
        {
            "key": "category", "title": "دسته‌بندی", "width": 120,
            "type": "badge",
            "badge_map": {
                "technical": {"label": "فنی", "color": "blue"},
                "resource": {"label": "منابع", "color": "purple"},
                "schedule": {"label": "زمان‌بندی", "color": "orange"},
                "cost": {"label": "هزینه", "color": "red"},
                "scope": {"label": "دامنه", "color": "indigo"},
                "quality": {"label": "کیفیت", "color": "teal"},
                "communication": {"label": "ارتباطات", "color": "cyan"},
                "other": {"label": "سایر", "color": "gray"},
            },
        },
        {
            "key": "severity", "title": "شدت", "width": 100,
            "type": "badge",
            "badge_map": {
                "critical": {"label": "بحرانی", "color": "red"},
                "major": {"label": "عمده", "color": "orange"},
                "moderate": {"label": "متوسط", "color": "yellow"},
                "minor": {"label": "جزئی", "color": "green"},
            },
        },
        {
            "key": "priority", "title": "اولویت", "width": 100,
            "type": "badge",
            "badge_map": {
                "critical": {"label": "بحرانی", "color": "red"},
                "high": {"label": "بالا", "color": "orange"},
                "medium": {"label": "متوسط", "color": "yellow"},
                "low": {"label": "پایین", "color": "green"},
            },
        },
        {
            "key": "status", "title": "وضعیت", "width": 120,
            "type": "badge",
            "badge_map": {
                "open": {"label": "باز", "color": "blue"},
                "in_progress": {"label": "در حال رسیدگی", "color": "yellow"},
                "on_hold": {"label": "متوقف", "color": "gray"},
                "resolved": {"label": "حل‌شده", "color": "green"},
                "closed": {"label": "بسته‌شده", "color": "slate"},
            },
        },
        {"key": "assignee_name", "title": "مسئول رسیدگی", "width": 150},
        {"key": "identified_date", "title": "تاریخ شناسایی", "width": 120, "type": "date_jalali"},
        {"key": "due_date", "title": "مهلت رسیدگی", "width": 120, "type": "date_jalali"},
    ],
    "filters": [
        {"key": "project", "label": "پروژه", "type": "lookup", "lookup_endpoint": "/api/v1/pm/projects/"},
        {
            "key": "status", "label": "وضعیت", "type": "select",
            "options": [
                {"value": "open", "label": "باز"},
                {"value": "in_progress", "label": "در حال رسیدگی"},
                {"value": "on_hold", "label": "متوقف"},
                {"value": "resolved", "label": "حل‌شده"},
                {"value": "closed", "label": "بسته‌شده"},
            ],
        },
        {
            "key": "severity", "label": "شدت", "type": "select",
            "options": [
                {"value": "critical", "label": "بحرانی"},
                {"value": "major", "label": "عمده"},
                {"value": "moderate", "label": "متوسط"},
                {"value": "minor", "label": "جزئی"},
            ],
        },
        {
            "key": "priority", "label": "اولویت", "type": "select",
            "options": [
                {"value": "critical", "label": "بحرانی"},
                {"value": "high", "label": "بالا"},
                {"value": "medium", "label": "متوسط"},
                {"value": "low", "label": "پایین"},
            ],
        },
        {"key": "assignee", "label": "مسئول رسیدگی", "type": "lookup", "lookup_endpoint": "/api/v1/auth/users/"},
    ],
    "search_fields": ["code", "title", "description"],
    "default_sort": "-created_at",
    "actions": {
        "row": [
            {"key": "view", "label": "مشاهده", "icon": "HiOutlineEye"},
            {"key": "edit", "label": "ویرایش", "icon": "HiOutlinePencilSquare", "permission": "pm.issue.update"},
            {"key": "delete", "label": "حذف", "icon": "HiOutlineTrash", "permission": "pm.issue.delete", "confirm": True},
        ],
        "bulk": [
            {"key": "export", "label": "خروجی", "icon": "HiOutlineArrowDownTray", "permission": "pm.issue.list"},
        ],
    },
}


# ═══════════════════════════════════════════════════
# OBS Table
# ═══════════════════════════════════════════════════

OBS_TABLE = {
    "id": "pm_obs_table",
    "title": "ساختار شکست سازمانی (OBS)",
    "endpoint": "/api/v1/pm/obs-nodes/",
    "columns": [
        {"key": "code", "label": "کد", "sortable": True, "width": 100},
        {"key": "name", "label": "نام", "sortable": True, "width": 200},
        {
            "key": "node_type", "label": "نوع", "sortable": True, "width": 120,
            "badge_map": {
                "department": {"label": "دپارتمان", "color": "blue"},
                "division": {"label": "بخش", "color": "purple"},
                "team": {"label": "تیم", "color": "green"},
                "individual": {"label": "فرد", "color": "orange"},
                "external": {"label": "خارجی", "color": "gray"},
            },
        },
        {"key": "level", "label": "سطح", "sortable": True, "width": 70},
        {"key": "manager", "label": "مدیر/مسئول", "sortable": True, "width": 150},
        {
            "key": "is_active", "label": "وضعیت", "sortable": True, "width": 90,
            "badge_map": {
                True: {"label": "فعال", "color": "green"},
                False: {"label": "غیرفعال", "color": "gray"},
            },
        },
        {"key": "sort_order", "label": "ترتیب", "sortable": True, "width": 70},
        {"key": "created_at", "label": "تاریخ ایجاد", "sortable": True, "type": "date_jalali", "width": 130},
    ],
    "filters": [
        {"key": "project", "label": "پروژه", "type": "lookup", "lookup_endpoint": "/api/v1/pm/projects/"},
        {
            "key": "node_type", "label": "نوع گره", "type": "select",
            "options": [
                {"value": "department", "label": "دپارتمان"},
                {"value": "division", "label": "بخش"},
                {"value": "team", "label": "تیم"},
                {"value": "individual", "label": "فرد"},
                {"value": "external", "label": "خارجی"},
            ],
        },
        {"key": "is_active", "label": "فعال", "type": "boolean"},
        {"key": "manager", "label": "مدیر", "type": "lookup", "lookup_endpoint": "/api/v1/auth/users/"},
    ],
    "search_fields": ["code", "name", "responsibilities"],
    "default_sort": "sort_order",
    "actions": {
        "row": [
            {"key": "view", "label": "مشاهده", "icon": "HiOutlineEye"},
            {"key": "edit", "label": "ویرایش", "icon": "HiOutlinePencilSquare", "permission": "pm.obs.update"},
            {"key": "children", "label": "فرزندان", "icon": "HiOutlineListBullet"},
            {"key": "delete", "label": "حذف", "icon": "HiOutlineTrash", "permission": "pm.obs.delete", "confirm": True},
        ],
        "bulk": [
            {"key": "export", "label": "خروجی", "icon": "HiOutlineArrowDownTray", "permission": "pm.obs.list"},
        ],
    },
}


# ═══════════════════════════════════════════════════
# RBS Table
# ═══════════════════════════════════════════════════

RBS_TABLE = {
    "id": "pm_rbs_table",
    "title": "ساختار شکست منابع (RBS)",
    "endpoint": "/api/v1/pm/rbs-nodes/",
    "columns": [
        {"key": "code", "label": "کد", "sortable": True, "width": 100},
        {"key": "name", "label": "نام", "sortable": True, "width": 200},
        {
            "key": "node_type", "label": "نوع", "sortable": True, "width": 120,
            "badge_map": {
                "category": {"label": "دسته‌بندی", "color": "blue"},
                "human": {"label": "نیروی انسانی", "color": "green"},
                "equipment": {"label": "تجهیزات", "color": "purple"},
                "material": {"label": "مواد", "color": "orange"},
                "facility": {"label": "تسهیلات", "color": "teal"},
                "financial": {"label": "مالی", "color": "yellow"},
                "information": {"label": "اطلاعاتی", "color": "gray"},
            },
        },
        {"key": "level", "label": "سطح", "sortable": True, "width": 70},
        {"key": "resource_type", "label": "نوع منبع", "sortable": True, "width": 130},
        {"key": "unit", "label": "واحد", "sortable": True, "width": 90},
        {"key": "default_rate", "label": "نرخ پیش‌فرض", "sortable": True, "type": "currency", "width": 130},
        {
            "key": "is_active", "label": "وضعیت", "sortable": True, "width": 90,
            "badge_map": {
                True: {"label": "فعال", "color": "green"},
                False: {"label": "غیرفعال", "color": "gray"},
            },
        },
        {"key": "sort_order", "label": "ترتیب", "sortable": True, "width": 70},
        {"key": "created_at", "label": "تاریخ ایجاد", "sortable": True, "type": "date_jalali", "width": 130},
    ],
    "filters": [
        {"key": "project", "label": "پروژه", "type": "lookup", "lookup_endpoint": "/api/v1/pm/projects/"},
        {
            "key": "node_type", "label": "نوع گره", "type": "select",
            "options": [
                {"value": "category", "label": "دسته‌بندی"},
                {"value": "human", "label": "نیروی انسانی"},
                {"value": "equipment", "label": "تجهیزات"},
                {"value": "material", "label": "مواد"},
                {"value": "facility", "label": "تسهیلات"},
                {"value": "financial", "label": "مالی"},
                {"value": "information", "label": "اطلاعاتی"},
            ],
        },
        {"key": "resource_type", "label": "نوع منبع", "type": "text"},
        {"key": "is_active", "label": "فعال", "type": "boolean"},
    ],
    "search_fields": ["code", "name", "resource_type", "unit"],
    "default_sort": "sort_order",
    "actions": {
        "row": [
            {"key": "view", "label": "مشاهده", "icon": "HiOutlineEye"},
            {"key": "edit", "label": "ویرایش", "icon": "HiOutlinePencilSquare", "permission": "pm.rbs.update"},
            {"key": "children", "label": "فرزندان", "icon": "HiOutlineListBullet"},
            {"key": "delete", "label": "حذف", "icon": "HiOutlineTrash", "permission": "pm.rbs.delete", "confirm": True},
        ],
        "bulk": [
            {"key": "export", "label": "خروجی", "icon": "HiOutlineArrowDownTray", "permission": "pm.rbs.list"},
        ],
    },
}


# ═══════════════════════════════════════════════════
# Quality Plan Table
# ═══════════════════════════════════════════════════

QUALITY_PLAN_TABLE = {
    "id": "pm_quality_plan_table",
    "title": "طرح‌های کیفیت",
    "endpoint": "/api/v1/pm/quality-plans/",
    "columns": [
        {"key": "name", "label": "نام", "sortable": True, "width": 200},
        {
            "key": "status", "label": "وضعیت", "sortable": True, "width": 120,
            "badge_map": {
                "draft": {"label": "پیش‌نویس", "color": "gray"},
                "active": {"label": "فعال", "color": "green"},
                "under_review": {"label": "در حال بررسی", "color": "yellow"},
                "approved": {"label": "تأیید شده", "color": "blue"},
                "archived": {"label": "بایگانی", "color": "red"},
            },
        },
        {"key": "version", "label": "نسخه", "sortable": True, "width": 80},
        {"key": "effective_date", "label": "تاریخ مؤثر", "sortable": True, "type": "date_jalali", "width": 130},
        {"key": "review_date", "label": "تاریخ بازبینی", "sortable": True, "type": "date_jalali", "width": 130},
        {"key": "created_at", "label": "تاریخ ایجاد", "sortable": True, "type": "date_jalali", "width": 130},
    ],
    "filters": [
        {"key": "project", "label": "پروژه", "type": "lookup", "lookup_endpoint": "/api/v1/pm/projects/"},
        {
            "key": "status", "label": "وضعیت", "type": "select",
            "options": [
                {"value": "draft", "label": "پیش‌نویس"},
                {"value": "active", "label": "فعال"},
                {"value": "under_review", "label": "در حال بررسی"},
                {"value": "approved", "label": "تأیید شده"},
                {"value": "archived", "label": "بایگانی"},
            ],
        },
    ],
    "search_fields": ["name", "criteria", "standards"],
    "default_sort": "-created_at",
    "actions": {
        "row": [
            {"key": "view", "label": "مشاهده", "icon": "HiOutlineEye"},
            {"key": "edit", "label": "ویرایش", "icon": "HiOutlinePencilSquare", "permission": "pm.quality_plan.update"},
            {"key": "delete", "label": "حذف", "icon": "HiOutlineTrash", "permission": "pm.quality_plan.delete", "confirm": True},
        ],
        "bulk": [
            {"key": "export", "label": "خروجی", "icon": "HiOutlineArrowDownTray", "permission": "pm.quality_plan.list"},
        ],
    },
}


# ═══════════════════════════════════════════════════
# Inspection Table
# ═══════════════════════════════════════════════════

INSPECTION_TABLE = {
    "id": "pm_inspection_table",
    "title": "بازرسی‌ها",
    "endpoint": "/api/v1/pm/inspections/",
    "columns": [
        {"key": "code", "label": "کد", "sortable": True, "width": 100},
        {"key": "title", "label": "عنوان", "sortable": True, "width": 200},
        {
            "key": "inspection_type", "label": "نوع", "sortable": True, "width": 130,
            "badge_map": {
                "quality_audit": {"label": "ممیزی کیفیت", "color": "blue"},
                "process_inspection": {"label": "بازرسی فرآیند", "color": "purple"},
                "product_inspection": {"label": "بازرسی محصول", "color": "green"},
                "milestone_review": {"label": "بازبینی نقطه عطف", "color": "orange"},
                "final_inspection": {"label": "بازرسی نهایی", "color": "red"},
                "random_sampling": {"label": "نمونه‌برداری", "color": "teal"},
            },
        },
        {
            "key": "status", "label": "وضعیت", "sortable": True, "width": 110,
            "badge_map": {
                "planned": {"label": "برنامه‌ریزی شده", "color": "gray"},
                "in_progress": {"label": "در حال انجام", "color": "blue"},
                "completed": {"label": "انجام شده", "color": "green"},
                "cancelled": {"label": "لغو شده", "color": "red"},
            },
        },
        {
            "key": "result", "label": "نتیجه", "sortable": True, "width": 100,
            "badge_map": {
                "passed": {"label": "قبول", "color": "green"},
                "failed": {"label": "مردود", "color": "red"},
                "conditional": {"label": "مشروط", "color": "yellow"},
                "na": {"label": "نامشخص", "color": "gray"},
            },
        },
        {"key": "planned_date", "label": "تاریخ برنامه", "sortable": True, "type": "date_jalali", "width": 130},
        {"key": "actual_date", "label": "تاریخ واقعی", "sortable": True, "type": "date_jalali", "width": 130},
        {"key": "created_at", "label": "تاریخ ایجاد", "sortable": True, "type": "date_jalali", "width": 130},
    ],
    "filters": [
        {"key": "project", "label": "پروژه", "type": "lookup", "lookup_endpoint": "/api/v1/pm/projects/"},
        {
            "key": "status", "label": "وضعیت", "type": "select",
            "options": [
                {"value": "planned", "label": "برنامه‌ریزی شده"},
                {"value": "in_progress", "label": "در حال انجام"},
                {"value": "completed", "label": "انجام شده"},
                {"value": "cancelled", "label": "لغو شده"},
            ],
        },
        {
            "key": "result", "label": "نتیجه", "type": "select",
            "options": [
                {"value": "passed", "label": "قبول"},
                {"value": "failed", "label": "مردود"},
                {"value": "conditional", "label": "مشروط"},
                {"value": "na", "label": "نامشخص"},
            ],
        },
    ],
    "search_fields": ["code", "title", "findings"],
    "default_sort": "-planned_date",
    "actions": {
        "row": [
            {"key": "view", "label": "مشاهده", "icon": "HiOutlineEye"},
            {"key": "edit", "label": "ویرایش", "icon": "HiOutlinePencilSquare", "permission": "pm.inspection.update"},
            {"key": "delete", "label": "حذف", "icon": "HiOutlineTrash", "permission": "pm.inspection.delete", "confirm": True},
        ],
        "bulk": [
            {"key": "export", "label": "خروجی", "icon": "HiOutlineArrowDownTray", "permission": "pm.inspection.list"},
        ],
    },
}


# ═══════════════════════════════════════════════════
# NCR Table
# ═══════════════════════════════════════════════════

NCR_TABLE = {
    "id": "pm_ncr_table",
    "title": "عدم انطباق‌ها (NCR)",
    "endpoint": "/api/v1/pm/ncrs/",
    "columns": [
        {"key": "code", "label": "کد", "sortable": True, "width": 100},
        {"key": "title", "label": "عنوان", "sortable": True, "width": 200},
        {
            "key": "severity", "label": "شدت", "sortable": True, "width": 100,
            "badge_map": {
                "minor": {"label": "جزئی", "color": "green"},
                "major": {"label": "عمده", "color": "yellow"},
                "critical": {"label": "بحرانی", "color": "red"},
            },
        },
        {
            "key": "status", "label": "وضعیت", "sortable": True, "width": 120,
            "badge_map": {
                "open": {"label": "باز", "color": "gray"},
                "under_review": {"label": "بررسی", "color": "blue"},
                "action_required": {"label": "نیاز به اقدام", "color": "orange"},
                "in_progress": {"label": "در حال رفع", "color": "purple"},
                "resolved": {"label": "رفع شده", "color": "green"},
                "verified": {"label": "تأیید شده", "color": "teal"},
                "closed": {"label": "بسته شده", "color": "gray"},
            },
        },
        {"key": "identified_date", "label": "تاریخ شناسایی", "sortable": True, "type": "date_jalali", "width": 130},
        {"key": "due_date", "label": "مهلت", "sortable": True, "type": "date_jalali", "width": 130},
        {"key": "cost_impact", "label": "اثر هزینه", "sortable": True, "type": "currency", "width": 130},
        {"key": "created_at", "label": "تاریخ ایجاد", "sortable": True, "type": "date_jalali", "width": 130},
    ],
    "filters": [
        {"key": "project", "label": "پروژه", "type": "lookup", "lookup_endpoint": "/api/v1/pm/projects/"},
        {
            "key": "severity", "label": "شدت", "type": "select",
            "options": [
                {"value": "minor", "label": "جزئی"},
                {"value": "major", "label": "عمده"},
                {"value": "critical", "label": "بحرانی"},
            ],
        },
        {
            "key": "status", "label": "وضعیت", "type": "select",
            "options": [
                {"value": "open", "label": "باز"},
                {"value": "under_review", "label": "بررسی"},
                {"value": "action_required", "label": "نیاز به اقدام"},
                {"value": "in_progress", "label": "در حال رفع"},
                {"value": "resolved", "label": "رفع شده"},
                {"value": "verified", "label": "تأیید شده"},
                {"value": "closed", "label": "بسته شده"},
            ],
        },
    ],
    "search_fields": ["code", "title", "root_cause", "corrective_action"],
    "default_sort": "-created_at",
    "actions": {
        "row": [
            {"key": "view", "label": "مشاهده", "icon": "HiOutlineEye"},
            {"key": "edit", "label": "ویرایش", "icon": "HiOutlinePencilSquare", "permission": "pm.ncr.update"},
            {"key": "delete", "label": "حذف", "icon": "HiOutlineTrash", "permission": "pm.ncr.delete", "confirm": True},
        ],
        "bulk": [
            {"key": "export", "label": "خروجی", "icon": "HiOutlineArrowDownTray", "permission": "pm.ncr.list"},
        ],
    },
}


# ═══════════════════════════════════════════════════
# Quality Checklist Table
# ═══════════════════════════════════════════════════

QUALITY_CHECKLIST_TABLE = {
    "id": "pm_quality_checklist_table",
    "title": "چک‌لیست‌های کیفیت",
    "endpoint": "/api/v1/pm/quality-checklists/",
    "columns": [
        {"key": "name", "label": "نام", "sortable": True, "width": 200},
        {"key": "quality_plan", "label": "طرح کیفیت", "sortable": True, "width": 160},
        {"key": "task", "label": "فعالیت", "sortable": True, "width": 160},
        {
            "key": "is_completed", "label": "وضعیت", "sortable": True, "width": 100,
            "badge_map": {
                True: {"label": "تکمیل", "color": "green"},
                False: {"label": "ناتمام", "color": "gray"},
            },
        },
        {"key": "items_count", "label": "تعداد آیتم", "width": 90},
        {"key": "completed_date", "label": "تاریخ تکمیل", "sortable": True, "type": "date_jalali", "width": 130},
        {"key": "created_at", "label": "تاریخ ایجاد", "sortable": True, "type": "date_jalali", "width": 130},
    ],
    "filters": [
        {"key": "project", "label": "پروژه", "type": "lookup", "lookup_endpoint": "/api/v1/pm/projects/"},
        {"key": "is_completed", "label": "تکمیل شده", "type": "boolean"},
    ],
    "search_fields": ["name", "description"],
    "default_sort": "-created_at",
    "actions": {
        "row": [
            {"key": "view", "label": "مشاهده", "icon": "HiOutlineEye"},
            {"key": "edit", "label": "ویرایش", "icon": "HiOutlinePencilSquare", "permission": "pm.quality_checklist.update"},
            {"key": "delete", "label": "حذف", "icon": "HiOutlineTrash", "permission": "pm.quality_checklist.delete", "confirm": True},
        ],
        "bulk": [
            {"key": "export", "label": "خروجی", "icon": "HiOutlineArrowDownTray", "permission": "pm.quality_checklist.list"},
        ],
    },
}


# ═══════════════════════════════════════════════════
# Project Document Table
# ═══════════════════════════════════════════════════

PROJECT_DOCUMENT_TABLE = {
    "id": "pm_project_document_table",
    "title": "مستندات پروژه",
    "endpoint": "/api/v1/pm/project-documents/",
    "columns": [
        {"key": "title", "label": "عنوان", "sortable": True, "width": 200},
        {"key": "document_code", "label": "کد سند", "sortable": True, "width": 140},
        {"key": "entity_type", "label": "نوع موجودیت", "sortable": True, "width": 120},
        {"key": "linked_by_name", "label": "لینک‌دهنده", "width": 150},
        {"key": "notes", "label": "یادداشت", "width": 200},
        {"key": "created_at", "label": "تاریخ لینک", "sortable": True, "type": "date_jalali", "width": 130},
    ],
    "filters": [
        {"key": "project", "label": "پروژه", "type": "lookup", "lookup_endpoint": "/api/v1/pm/projects/"},
        {"key": "entity_type", "label": "نوع موجودیت", "type": "text"},
    ],
    "search_fields": ["title", "document_code", "notes"],
    "default_sort": "-created_at",
    "actions": {
        "row": [
            {"key": "view", "label": "مشاهده", "icon": "HiOutlineEye"},
            {"key": "delete", "label": "حذف لینک", "icon": "HiOutlineTrash", "permission": "pm.project_document.delete", "confirm": True},
        ],
        "bulk": [
            {"key": "export", "label": "خروجی", "icon": "HiOutlineArrowDownTray", "permission": "pm.project_document.list"},
        ],
    },
}
