const PermissionCategory = {
    PAGE: 'page',
    ACTION: 'action'
}

/** 抢课助手页面：抢课权限或任一抢课管理页权限均可访问 */
const QK_ASSISTANT_ACCESS_CODES = [
    'page.qk.taskList',
    'page.admin.qk.client',
    'page.admin.qk.batch',
    'page.admin.qk.task',
    'page.admin.qk.report'
]

const QK_ASSISTANT_SUBMIT_CODES = [
    'action.qk.task.submit',
    'action.qk.admin.taskManage'
]

const QK_ASSISTANT_CONTROL_CODES = [
    'action.qk.task.control',
    'action.qk.admin.taskManage'
]

const DEFAULT_PERMISSION_POINTS = [
    { code: 'page.admin.userList', name: '用户管理', category: PermissionCategory.PAGE, scope_type: 'page', page_route_name: 'admin.userList', remark: '访问后台用户管理页面' },
    { code: 'page.admin.lepaoAccount', name: '乐跑账号管理', category: PermissionCategory.PAGE, scope_type: 'page', page_route_name: 'admin.lepaoAccount', remark: '访问后台乐跑账号管理页面' },
    { code: 'page.admin.service.orderList', name: '工单管理', category: PermissionCategory.PAGE, scope_type: 'page', page_route_name: 'admin.service.orderList', remark: '访问后台工单管理页面' },
    { code: 'page.admin.goods.sendCountRequestList', name: '赠送审核', category: PermissionCategory.PAGE, scope_type: 'page', page_route_name: 'admin.goods.sendCountRequestList', remark: '访问乐跑次数赠送审核页面' },
    { code: 'page.service.createOrder', name: '提交工单', category: PermissionCategory.PAGE, scope_type: 'page', page_route_name: 'service.createOrder', remark: '访问用户提交工单页面' },
    { code: 'page.lepao.accountList', name: '乐跑账号', category: PermissionCategory.PAGE, scope_type: 'page', page_route_name: 'lepao.accountList', remark: '访问用户乐跑账号页面' },
    { code: 'page.qk.taskList', name: '抢课助手', category: PermissionCategory.PAGE, scope_type: 'page', page_route_name: 'qk.taskList', remark: '访问抢课助手任务列表；拥有抢课管理页权限的管理员也可直接访问' },
    { code: 'page.admin.qk.client', name: '抢课客户端管理', category: PermissionCategory.PAGE, scope_type: 'page', page_route_name: 'qkManage.client', remark: '访问后台抢课客户端管理页面' },
    { code: 'page.admin.qk.task', name: '抢课任务管理', category: PermissionCategory.PAGE, scope_type: 'page', page_route_name: 'qkManage.task', remark: '访问后台抢课任务管理页面' },
    { code: 'page.admin.qk.batch', name: '抢课批次管理', category: PermissionCategory.PAGE, scope_type: 'page', page_route_name: 'qkManage.batch', remark: '访问后台抢课批次管理页面' },
    { code: 'page.admin.qk.report', name: '抢课回报记录', category: PermissionCategory.PAGE, scope_type: 'page', page_route_name: 'qkManage.report', remark: '查看抢课客户端回报记录' },

    { code: 'action.user.changeCount', name: '更改乐跑次数', category: PermissionCategory.ACTION, scope_type: 'action', remark: '管理员调整用户乐跑次数' },
    { code: 'action.user.ban', name: '封禁账户', category: PermissionCategory.ACTION, scope_type: 'action', remark: '封禁或解封用户账户' },
    { code: 'action.user.permissionManage', name: '权限管理', category: PermissionCategory.ACTION, scope_type: 'action', remark: '查看和编辑用户权限、权限规则' },
    { code: 'action.user.setSendCountAutoApprove', name: '赠送免审配置', category: PermissionCategory.ACTION, scope_type: 'action', remark: '配置用户赠送乐跑次数免审白名单' },
    { code: 'action.lepao.addAccount', name: '新增乐跑账号', category: PermissionCategory.ACTION, scope_type: 'action', remark: '用户新增或绑定乐跑账号' },
    { code: 'action.lepao.singleRun', name: '发起单次乐跑', category: PermissionCategory.ACTION, scope_type: 'action', remark: '用户发起单次乐跑' },
    { code: 'action.lepao.changeAutoRun', name: '配置自动乐跑', category: PermissionCategory.ACTION, scope_type: 'action', remark: '用户开启或关闭自动乐跑' },
    { code: 'action.lepao.updateAccount', name: '更新乐跑账号', category: PermissionCategory.ACTION, scope_type: 'action', remark: '更新乐跑账号信息' },
    { code: 'action.lepao.deleteAccount', name: '解绑乐跑账号', category: PermissionCategory.ACTION, scope_type: 'action', remark: '解绑乐跑账号' },
    { code: 'action.lepao.admin.updateAccount', name: '后台更新乐跑账号', category: PermissionCategory.ACTION, scope_type: 'action', remark: '管理员更新乐跑账号信息' },
    { code: 'action.qk.task.submit', name: '提交抢课任务', category: PermissionCategory.ACTION, scope_type: 'action', remark: '提交、更新或取消抢课任务' },
    { code: 'action.qk.task.control', name: '控制抢课任务', category: PermissionCategory.ACTION, scope_type: 'action', remark: '开启或暂停抢课任务' },
    { code: 'action.qk.admin.clientManage', name: '管理抢课客户端', category: PermissionCategory.ACTION, scope_type: 'action', remark: '管理员禁用抢课客户端' },
    { code: 'action.qk.admin.batchManage', name: '管理抢课批次', category: PermissionCategory.ACTION, scope_type: 'action', remark: '管理员新建或编辑抢课批次' },
    { code: 'action.qk.admin.taskManage', name: '管理抢课任务', category: PermissionCategory.ACTION, scope_type: 'action', remark: '管理员编辑、重试或取消抢课任务' },
    { code: 'action.goods.sendCount', name: '赠送乐跑次数', category: PermissionCategory.ACTION, scope_type: 'action', remark: '用户向他人赠送乐跑次数' },
    { code: 'action.goods.reviewSendCount', name: '审核赠送次数', category: PermissionCategory.ACTION, scope_type: 'action', remark: '管理员审核乐跑次数赠送申请' },
    { code: 'action.service.createOrder', name: '发起工单', category: PermissionCategory.ACTION, scope_type: 'action', remark: '用户提交新工单或回复自己的工单' },
    { code: 'action.service.replyOrder', name: '回复工单', category: PermissionCategory.ACTION, scope_type: 'action', remark: '客服或管理员回复工单' }
]

const DEFAULT_PERMISSION_RESOURCE_RULES = [
    { resource_type: 'page', resource_key: 'admin.userList', required_codes: ['page.admin.userList'] },
    { resource_type: 'page', resource_key: 'admin.lepaoAccount', required_codes: ['page.admin.lepaoAccount'] },
    { resource_type: 'page', resource_key: 'admin.service.orderList', required_codes: ['page.admin.service.orderList'] },
    { resource_type: 'page', resource_key: 'admin.goods.sendCountRequestList', required_codes: ['page.admin.goods.sendCountRequestList'] },
    { resource_type: 'page', resource_key: 'service.createOrder', required_codes: ['page.service.createOrder'] },
    { resource_type: 'page', resource_key: 'lepao.accountList', required_codes: ['page.lepao.accountList'] },
    { resource_type: 'page', resource_key: 'qk.taskList', required_codes: QK_ASSISTANT_ACCESS_CODES },
    { resource_type: 'page', resource_key: 'qkManage.client', required_codes: ['page.admin.qk.client'] },
    { resource_type: 'page', resource_key: 'qkManage.task', required_codes: ['page.admin.qk.task'] },
    { resource_type: 'page', resource_key: 'qkManage.batch', required_codes: ['page.admin.qk.batch'] },
    { resource_type: 'page', resource_key: 'qkManage.report', required_codes: ['page.admin.qk.report'] },

    { resource_type: 'action', resource_key: 'action.user.changeCount', required_codes: ['action.user.changeCount'] },
    { resource_type: 'action', resource_key: 'action.user.ban', required_codes: ['action.user.ban'] },
    { resource_type: 'action', resource_key: 'action.user.permissionManage', required_codes: ['action.user.permissionManage'] },
    { resource_type: 'action', resource_key: 'action.user.setSendCountAutoApprove', required_codes: ['action.user.setSendCountAutoApprove'] },
    { resource_type: 'action', resource_key: 'action.lepao.addAccount', required_codes: ['action.lepao.addAccount'] },
    { resource_type: 'action', resource_key: 'action.lepao.singleRun', required_codes: ['action.lepao.singleRun'] },
    { resource_type: 'action', resource_key: 'action.lepao.changeAutoRun', required_codes: ['action.lepao.changeAutoRun'] },
    { resource_type: 'action', resource_key: 'action.lepao.updateAccount', required_codes: ['action.lepao.updateAccount'] },
    { resource_type: 'action', resource_key: 'action.lepao.deleteAccount', required_codes: ['action.lepao.deleteAccount'] },
    { resource_type: 'action', resource_key: 'action.lepao.admin.updateAccount', required_codes: ['action.lepao.admin.updateAccount'] },
    { resource_type: 'action', resource_key: 'action.qk.task.submit', required_codes: ['action.qk.task.submit'] },
    { resource_type: 'action', resource_key: 'action.qk.task.control', required_codes: ['action.qk.task.control'] },
    { resource_type: 'action', resource_key: 'action.qk.admin.clientManage', required_codes: ['action.qk.admin.clientManage'] },
    { resource_type: 'action', resource_key: 'action.qk.admin.batchManage', required_codes: ['action.qk.admin.batchManage'] },
    { resource_type: 'action', resource_key: 'action.qk.admin.taskManage', required_codes: ['action.qk.admin.taskManage'] },
    { resource_type: 'action', resource_key: 'action.goods.sendCount', required_codes: ['action.goods.sendCount'] },
    { resource_type: 'action', resource_key: 'action.goods.reviewSendCount', required_codes: ['action.goods.reviewSendCount'] },
    { resource_type: 'action', resource_key: 'action.service.createOrder', required_codes: ['action.service.createOrder'] },
    { resource_type: 'action', resource_key: 'action.service.replyOrder', required_codes: ['action.service.replyOrder'] },

    { resource_type: 'api', resource_key: 'GET /Admin/User/GetUserList', api_method: 'GET', api_path: '/Admin/User/GetUserList', required_codes: ['page.admin.userList'] },
    { resource_type: 'api', resource_key: 'POST /Admin/User/ChangeLepaoCount', api_method: 'POST', api_path: '/Admin/User/ChangeLepaoCount', required_codes: ['action.user.changeCount'] },
    { resource_type: 'api', resource_key: 'POST /Admin/User/SetUserBan', api_method: 'POST', api_path: '/Admin/User/SetUserBan', required_codes: ['action.user.ban'] },
    { resource_type: 'api', resource_key: 'POST /Admin/User/SetSendCountAutoApprove', api_method: 'POST', api_path: '/Admin/User/SetSendCountAutoApprove', required_codes: ['action.user.setSendCountAutoApprove'] },
    { resource_type: 'api', resource_key: 'GET /Admin/Lepao/Account', api_method: 'GET', api_path: '/Admin/Lepao/Account', required_codes: ['page.admin.lepaoAccount'] },
    { resource_type: 'api', resource_key: 'POST /Admin/Lepao/Account/UpdateAccountInfo', api_method: 'POST', api_path: '/Admin/Lepao/Account/UpdateAccountInfo', required_codes: ['action.lepao.admin.updateAccount'] },
    { resource_type: 'api', resource_key: 'POST /Lepao/Account', api_method: 'POST', api_path: '/Lepao/Account', required_codes: ['action.lepao.addAccount'] },
    { resource_type: 'api', resource_key: 'GET /Lepao/SingleRun', api_method: 'GET', api_path: '/Lepao/SingleRun', required_codes: ['action.lepao.singleRun'] },
    { resource_type: 'api', resource_key: 'GET /Lepao/ChangeAutoRun', api_method: 'GET', api_path: '/Lepao/ChangeAutoRun', required_codes: ['action.lepao.changeAutoRun'] },
    { resource_type: 'api', resource_key: 'POST /Lepao/Account/UpdateSelfAccount', api_method: 'POST', api_path: '/Lepao/Account/UpdateSelfAccount', required_codes: ['action.lepao.updateAccount'] },
    { resource_type: 'api', resource_key: 'DELETE /Lepao/Account', api_method: 'DELETE', api_path: '/Lepao/Account', required_codes: ['action.lepao.deleteAccount'] },
    { resource_type: 'api', resource_key: 'GET /QK/Task', api_method: 'GET', api_path: '/QK/Task', required_codes: QK_ASSISTANT_ACCESS_CODES },
    { resource_type: 'api', resource_key: 'GET /QK/Task/Detail', api_method: 'GET', api_path: '/QK/Task/Detail', required_codes: QK_ASSISTANT_ACCESS_CODES },
    { resource_type: 'api', resource_key: 'POST /QK/Task', api_method: 'POST', api_path: '/QK/Task', required_codes: QK_ASSISTANT_SUBMIT_CODES },
    { resource_type: 'api', resource_key: 'DELETE /QK/Task', api_method: 'DELETE', api_path: '/QK/Task', required_codes: QK_ASSISTANT_SUBMIT_CODES },
    { resource_type: 'api', resource_key: 'POST /QK/Task/Start', api_method: 'POST', api_path: '/QK/Task/Start', required_codes: QK_ASSISTANT_CONTROL_CODES },
    { resource_type: 'api', resource_key: 'POST /QK/Task/Pause', api_method: 'POST', api_path: '/QK/Task/Pause', required_codes: QK_ASSISTANT_CONTROL_CODES },
    { resource_type: 'api', resource_key: 'GET /Admin/QK/Client/List', api_method: 'GET', api_path: '/Admin/QK/Client/List', required_codes: ['page.admin.qk.client'] },
    { resource_type: 'api', resource_key: 'DELETE /Admin/QK/Client/Delete', api_method: 'DELETE', api_path: '/Admin/QK/Client/Delete', required_codes: ['action.qk.admin.clientManage'] },
    { resource_type: 'api', resource_key: 'POST /Admin/QK/Client/Enable', api_method: 'POST', api_path: '/Admin/QK/Client/Enable', required_codes: ['action.qk.admin.clientManage'] },
    { resource_type: 'api', resource_key: 'GET /Admin/QK/Task/List', api_method: 'GET', api_path: '/Admin/QK/Task/List', required_codes: ['page.admin.qk.task'] },
    { resource_type: 'api', resource_key: 'GET /Admin/QK/Task/Detail', api_method: 'GET', api_path: '/Admin/QK/Task/Detail', required_codes: ['page.admin.qk.task'] },
    { resource_type: 'api', resource_key: 'POST /Admin/QK/Task/Update', api_method: 'POST', api_path: '/Admin/QK/Task/Update', required_codes: ['action.qk.admin.taskManage'] },
    { resource_type: 'api', resource_key: 'DELETE /Admin/QK/Task/Cancel', api_method: 'DELETE', api_path: '/Admin/QK/Task/Cancel', required_codes: ['action.qk.admin.taskManage'] },
    { resource_type: 'api', resource_key: 'POST /Admin/QK/Task/Retry', api_method: 'POST', api_path: '/Admin/QK/Task/Retry', required_codes: ['action.qk.admin.taskManage'] },
    { resource_type: 'api', resource_key: 'POST /Admin/QK/Task/Start', api_method: 'POST', api_path: '/Admin/QK/Task/Start', required_codes: ['action.qk.admin.taskManage'] },
    { resource_type: 'api', resource_key: 'POST /Admin/QK/Task/Pause', api_method: 'POST', api_path: '/Admin/QK/Task/Pause', required_codes: ['action.qk.admin.taskManage'] },
    { resource_type: 'api', resource_key: 'GET /QK/Batch', api_method: 'GET', api_path: '/QK/Batch', required_codes: QK_ASSISTANT_ACCESS_CODES },
    { resource_type: 'api', resource_key: 'GET /Admin/QK/Batch/List', api_method: 'GET', api_path: '/Admin/QK/Batch/List', required_codes: ['page.admin.qk.batch'] },
    { resource_type: 'api', resource_key: 'POST /Admin/QK/Batch/Save', api_method: 'POST', api_path: '/Admin/QK/Batch/Save', required_codes: ['action.qk.admin.batchManage'] },
    { resource_type: 'api', resource_key: 'GET /Admin/QK/Report/List', api_method: 'GET', api_path: '/Admin/QK/Report/List', required_codes: ['page.admin.qk.report'] },
    { resource_type: 'api', resource_key: 'POST /Goods/SendCount', api_method: 'POST', api_path: '/Goods/SendCount', required_codes: ['action.goods.sendCount'] },
    { resource_type: 'api', resource_key: 'POST /Kefu/Order', api_method: 'POST', api_path: '/Kefu/Order', required_codes: ['action.service.createOrder'] },
    { resource_type: 'api', resource_key: 'GET /Admin/Kefu/Order', api_method: 'GET', api_path: '/Admin/Kefu/Order', required_codes: ['page.admin.service.orderList'] },
    { resource_type: 'api', resource_key: 'GET /Admin/Kefu/OrderDetail', api_method: 'GET', api_path: '/Admin/Kefu/OrderDetail', required_codes: ['page.admin.service.orderList'] },
    { resource_type: 'api', resource_key: 'PUT /Admin/Kefu/Order', api_method: 'PUT', api_path: '/Admin/Kefu/Order', required_codes: ['action.service.replyOrder'] },
    { resource_type: 'api', resource_key: 'GET /Admin/Goods/SendCountRequest/List', api_method: 'GET', api_path: '/Admin/Goods/SendCountRequest/List', required_codes: ['page.admin.goods.sendCountRequestList'] },
    { resource_type: 'api', resource_key: 'POST /Admin/Goods/SendCountRequest/Approve', api_method: 'POST', api_path: '/Admin/Goods/SendCountRequest/Approve', required_codes: ['action.goods.reviewSendCount'] },
    { resource_type: 'api', resource_key: 'POST /Admin/Goods/SendCountRequest/Reject', api_method: 'POST', api_path: '/Admin/Goods/SendCountRequest/Reject', required_codes: ['action.goods.reviewSendCount'] }
]

// 所有登录用户默认拥有的基础操作权限（无需在后台单独勾选）
const DEFAULT_BASIC_USER_PERMISSION_CODES = [
    'page.lepao.accountList',
    'action.lepao.addAccount',
    'action.lepao.singleRun',
    'action.lepao.changeAutoRun',
    'action.lepao.updateAccount',
    'action.lepao.deleteAccount',
    'action.goods.sendCount',
    'page.service.createOrder',
    'action.service.createOrder'
]

const LEGACY_ROLE_PERMISSION_MAP = {
    service: [
        'page.admin.userList',
        'page.admin.lepaoAccount',
        'page.admin.service.orderList',
        'page.admin.goods.sendCountRequestList',
        'action.user.changeCount',
        'action.user.ban',
        'action.user.setSendCountAutoApprove',
        'action.lepao.admin.updateAccount',
        'action.goods.reviewSendCount',
        'action.service.replyOrder'
    ],
    product: [
        'action.goods.reviewSendCount'
    ],
    path: []
}

module.exports = {
    DEFAULT_PERMISSION_POINTS,
    DEFAULT_PERMISSION_RESOURCE_RULES,
    DEFAULT_BASIC_USER_PERMISSION_CODES,
    LEGACY_ROLE_PERMISSION_MAP,
    QK_ASSISTANT_ACCESS_CODES,
    QK_ASSISTANT_SUBMIT_CODES,
    QK_ASSISTANT_CONTROL_CODES
}
