"""
HRM Workflow Definitions.

تعریف گردش‌کارهای ماژول HRM با استفاده از سرویس workflow پلتفرم.
"""

WORKFLOW_DEFINITIONS = {
    "hrm_leave_approval": {
        "name": "تأیید مرخصی",
        "description": "گردش‌کار تأیید درخواست مرخصی",
        "module": "hrm",
        "version": "1.0",
        "trigger": {
            "event": "hrm.leave.requested",
            "conditions": {
                "leave_policy__requires_approval": True,
            },
        },
        "steps": [
            {
                "id": "manager_approval",
                "name": "تأیید مدیر مستقیم",
                "type": "APPROVAL",
                "assignee_type": "ROLE",
                "assignee_resolver": "direct_manager",
                "timeout_hours": 48,
                "actions": {
                    "approve": {"next": "hr_review"},
                    "reject": {"next": "rejected"},
                },
            },
            {
                "id": "hr_review",
                "name": "بررسی منابع انسانی",
                "type": "APPROVAL",
                "assignee_type": "ROLE",
                "assignee_resolver": "hr_manager",
                "timeout_hours": 24,
                "conditions": {
                    "days_count__gt": 3,
                },
                "actions": {
                    "approve": {"next": "approved"},
                    "reject": {"next": "rejected"},
                },
            },
            {
                "id": "approved",
                "name": "تأیید شده",
                "type": "END",
                "on_enter": "hrm.leave.approve_action",
            },
            {
                "id": "rejected",
                "name": "رد شده",
                "type": "END",
                "on_enter": "hrm.leave.reject_action",
            },
        ],
    },
    "hrm_timesheet_approval": {
        "name": "تأیید تایم‌شیت",
        "description": "گردش‌کار تأیید تایم‌شیت",
        "module": "hrm",
        "version": "1.0",
        "trigger": {
            "event": "hrm.timesheet.submitted",
        },
        "steps": [
            {
                "id": "manager_approval",
                "name": "تأیید مدیر",
                "type": "APPROVAL",
                "assignee_type": "ROLE",
                "assignee_resolver": "direct_manager",
                "timeout_hours": 72,
                "actions": {
                    "approve": {"next": "approved"},
                    "reject": {"next": "rejected"},
                },
            },
            {
                "id": "approved",
                "name": "تأیید شده",
                "type": "END",
                "on_enter": "hrm.timesheet.approve_action",
            },
            {
                "id": "rejected",
                "name": "رد شده",
                "type": "END",
                "on_enter": "hrm.timesheet.reject_action",
            },
        ],
    },
    "hrm_employee_onboarding": {
        "name": "فرآیند پذیرش کارمند",
        "description": "گردش‌کار پذیرش کارمند جدید",
        "module": "hrm",
        "version": "1.0",
        "trigger": {
            "event": "hrm.employee.hired",
        },
        "steps": [
            {
                "id": "hr_setup",
                "name": "تنظیمات HR",
                "type": "TASK",
                "assignee_type": "ROLE",
                "assignee_resolver": "hr_specialist",
                "timeout_hours": 48,
                "checklist": [
                    "تکمیل پرونده",
                    "ثبت قرارداد",
                    "صدور کارت پرسنلی",
                    "معرفی به بیمه",
                ],
                "actions": {
                    "complete": {"next": "it_setup"},
                },
            },
            {
                "id": "it_setup",
                "name": "تنظیمات IT",
                "type": "TASK",
                "assignee_type": "ROLE",
                "assignee_resolver": "it_admin",
                "timeout_hours": 24,
                "checklist": [
                    "ایجاد حساب کاربری",
                    "تخصیص ایمیل",
                    "تنظیم دسترسی‌ها",
                ],
                "actions": {
                    "complete": {"next": "completed"},
                },
            },
            {
                "id": "completed",
                "name": "تکمیل شده",
                "type": "END",
            },
        ],
    },
    "hrm_employee_termination": {
        "name": "فرآیند خاتمه همکاری",
        "description": "گردش‌کار خاتمه همکاری کارمند",
        "module": "hrm",
        "version": "1.0",
        "trigger": {
            "event": "hrm.employee.terminated",
        },
        "steps": [
            {
                "id": "hr_clearance",
                "name": "تسویه حساب HR",
                "type": "TASK",
                "assignee_type": "ROLE",
                "assignee_resolver": "hr_specialist",
                "timeout_hours": 72,
                "checklist": [
                    "محاسبه مرخصی مانده",
                    "محاسبه سنوات",
                    "تسویه بیمه",
                ],
                "actions": {
                    "complete": {"next": "finance_clearance"},
                },
            },
            {
                "id": "finance_clearance",
                "name": "تسویه مالی",
                "type": "TASK",
                "assignee_type": "ROLE",
                "assignee_resolver": "finance_manager",
                "timeout_hours": 72,
                "actions": {
                    "complete": {"next": "it_revoke"},
                },
            },
            {
                "id": "it_revoke",
                "name": "لغو دسترسی‌ها",
                "type": "TASK",
                "assignee_type": "ROLE",
                "assignee_resolver": "it_admin",
                "timeout_hours": 24,
                "checklist": [
                    "غیرفعال‌سازی حساب",
                    "بازپس‌گیری تجهیزات",
                ],
                "actions": {
                    "complete": {"next": "completed"},
                },
            },
            {
                "id": "completed",
                "name": "تکمیل شده",
                "type": "END",
            },
        ],
    },
}
