"""商家子客服权限码与常量（码表冻结，只增不改）。"""

CLUB_ID_DEFAULT = 'xq'

MEMBER_STATUS_ACTIVE = 1
MEMBER_STATUS_DISABLED = 0
MEMBER_STATUS_REMOVED = 2

INVITE_STATUS_UNUSED = 0
INVITE_STATUS_USED = 1
INVITE_STATUS_REVOKED = 2
INVITE_STATUS_EXPIRED = 3

ACTOR_MERCHANT = 'MERCHANT'
ACTOR_STAFF = 'STAFF'

# 商家订单操作流水行为码（数字，同一订单可重复记录）
ACTION_SETTLE = 1
ACTION_CANCEL = 2
ACTION_REFUND_APPLY = 3
ACTION_REFUND_CANCEL = 4
ACTION_REFUND_MODIFY = 5
ACTION_PENALTY_APPLY = 6
ACTION_PENALTY_CANCEL = 7
ACTION_PENALTY_MODIFY = 8
ACTION_PENALTY_RESUBMIT = 9
ACTION_CHANGE_PLAYER = 10
ACTION_DISPATCH = 11

ORDER_ACTION_LABELS = {
    ACTION_SETTLE: '结算',
    ACTION_CANCEL: '撤销订单',
    ACTION_REFUND_APPLY: '申请退款',
    ACTION_REFUND_CANCEL: '取消退款',
    ACTION_REFUND_MODIFY: '修改退款理由',
    ACTION_PENALTY_APPLY: '申请罚单',
    ACTION_PENALTY_CANCEL: '撤销罚单',
    ACTION_PENALTY_MODIFY: '修改罚单',
    ACTION_PENALTY_RESUBMIT: '重新申请罚单',
    ACTION_CHANGE_PLAYER: '更换打手',
    ACTION_DISPATCH: '派单',
}

WALLET_ALLOCATE = 'ALLOCATE'
WALLET_DISPATCH_FREEZE = 'DISPATCH_FREEZE'
WALLET_DISPATCH_CONFIRM = 'DISPATCH_CONFIRM'
WALLET_REFUND_RELEASE = 'REFUND_RELEASE'
WALLET_REVOKE = 'REVOKE'
WALLET_ADJUST = 'ADJUST'

STAT_ACTION_DISPATCH = 1
STAT_ACTION_SETTLE = 2
STAT_ACTION_REFUND = 3

# perm_code -> 中文名
PERMISSION_DEFINITIONS = [
    ('staff_manage', '子客服管理'),
    ('role_manage', '角色管理'),
    ('wallet_allocate', '划额度'),
    ('wallet_revoke', '收回额度'),
    ('wallet_view', '查看额度'),
    ('finance_view', '查看商家余额'),
    ('order_dispatch', '派单发单'),
    ('order_view_all', '查看全部订单'),
    ('order_view_self', '只看自己派的单'),
    ('order_detail', '订单详情'),
    ('order_settle', '结单'),
    ('order_refund_apply', '申请退款'),
    ('order_cancel', '撤销订单'),
    ('order_change_player', '换打手'),
    ('penalty_apply', '申请罚单'),
    ('penalty_manage', '改撤罚单'),
    ('penalty_view', '查看罚单'),
    ('staff_disable', '封禁解封客服'),
    ('template_manage', '派单模板'),
    ('audit_view', '操作日志'),
    ('rank_view', '客服排行榜'),
    ('im_chat', '订单IM'),
    ('stats_view', '统计数据'),
]

# 系统预置角色 -> 默认权限
SYSTEM_ROLE_TEMPLATES = [
    {
        'role_code': 'CHIEF',
        'role_name': '总管',
        'sort_order': 100,
        'permissions': [
            'staff_manage', 'wallet_allocate', 'wallet_revoke', 'wallet_view', 'finance_view',
            'order_dispatch', 'order_view_all', 'order_detail', 'order_settle',
            'order_refund_apply', 'order_cancel', 'order_change_player',
            'penalty_apply', 'penalty_manage', 'penalty_view', 'staff_disable',
            'template_manage', 'audit_view', 'rank_view', 'im_chat', 'stats_view',
        ],
    },
    {
        'role_code': 'FINANCE',
        'role_name': '财务',
        'sort_order': 80,
        'permissions': [
            'wallet_allocate', 'wallet_revoke', 'wallet_view', 'finance_view', 'order_view_all',
            'order_detail', 'penalty_view', 'audit_view', 'rank_view', 'stats_view',
        ],
    },
    {
        'role_code': 'DISPATCHER',
        'role_name': '派单员',
        'sort_order': 60,
        'permissions': [
            'wallet_view', 'order_dispatch', 'order_view_self', 'order_detail',
            'rank_view', 'im_chat', 'stats_view',
        ],
    },
]

OWNER_ALL_PERMISSIONS = [code for code, _ in PERMISSION_DEFINITIONS]

# 操作审计：仅展示「重要行为」，不含查看类
IMPORTANT_AUDIT_ACTIONS = frozenset([
    'DISPATCH', 'LINK_GENERATE', 'SETTLE', 'CANCEL', 'REFUND_APPLY',
    'CHANGE_PLAYER', 'PENALTY_APPLY', 'PENALTY_MANAGE',
    'TEMPLATE_CREATE', 'TEMPLATE_UPDATE', 'TEMPLATE_DELETE',
    'WALLET_ALLOCATE', 'WALLET_REVOKE', 'INVITE_CREATE', 'INVITE_REVOKE',
    'MEMBER_UPDATE_ROLE', 'MEMBER_REMOVE', 'MEMBER_DISABLE', 'MEMBER_ENABLE',
    'ROLE_CREATE', 'ROLE_SET_PERMS', 'MEMBER_SET_PERMS',
    'STAFF_BIND',
])

AUDIT_ACTION_LABELS = {
    'DISPATCH': '派单发单',
    'LINK_GENERATE': '生成链接',
    'SETTLE': '结单',
    'CANCEL': '撤销订单',
    'REFUND_APPLY': '申请退款',
    'CHANGE_PLAYER': '更换打手',
    'PENALTY_APPLY': '申请罚单',
    'PENALTY_MANAGE': '改撤罚单',
    'TEMPLATE_CREATE': '新增模板',
    'TEMPLATE_UPDATE': '修改模板',
    'TEMPLATE_DELETE': '删除模板',
    'WALLET_ALLOCATE': '划额度',
    'WALLET_REVOKE': '收回额度',
    'INVITE_CREATE': '生成邀请码',
    'INVITE_REVOKE': '作废邀请码',
    'MEMBER_UPDATE_ROLE': '更换客服角色',
    'MEMBER_REMOVE': '移除客服',
    'MEMBER_DISABLE': '禁用客服',
    'MEMBER_ENABLE': '启用客服',
    'ROLE_CREATE': '创建角色',
    'ROLE_SET_PERMS': '设置角色权限',
    'MEMBER_SET_PERMS': '调整成员权限',
    'STAFF_BIND': '客服绑定入驻',
    'ORDER_DETAIL': '查看订单详情',
}
