package service

import "strings"

type apiMetadataValue struct{ group, description string }

var apiMetadata = map[string]apiMetadataValue{
	"DELETE /api/deleteApisByIds":                              {group: "api", description: "批量删除api"},
	"DELETE /dataAccessLog/deleteDataAccessLogByIds":           {group: "数据权限审计", description: "批量删除数据权限审计日志"},
	"DELETE /department/deleteDepartment":                      {group: "部门", description: "删除部门"},
	"DELETE /info/deleteInfo":                                  {group: "公告", description: "删除公告"},
	"DELETE /info/deleteInfoByIds":                             {group: "公告", description: "批量删除公告"},
	"DELETE /mediaUpload/:uploadId":                            {group: "媒体上传", description: "取消大文件上传"},
	"DELETE /position/deletePosition":                          {group: "岗位", description: "删除岗位"},
	"DELETE /sysDictionary/deleteSysDictionary":                {group: "系统字典", description: "删除字典"},
	"DELETE /sysDictionaryDetail/deleteSysDictionaryDetail":    {group: "系统字典详情", description: "删除字典内容"},
	"DELETE /sysError/deleteSysError":                          {group: "错误日志", description: "删除错误日志"},
	"DELETE /sysError/deleteSysErrorByIds":                     {group: "错误日志", description: "批量删除错误日志"},
	"DELETE /sysExportTemplate/deleteSysExportTemplate":        {group: "导出模板", description: "删除导出模板"},
	"DELETE /sysExportTemplate/deleteSysExportTemplateByIds":   {group: "导出模板", description: "批量删除导出模板"},
	"DELETE /sysLoginLog/deleteLoginLog":                       {group: "登录日志", description: "删除登录日志"},
	"DELETE /sysLoginLog/deleteLoginLogByIds":                  {group: "登录日志", description: "批量删除登录日志"},
	"DELETE /sysOperationRecord/deleteSysOperationRecord":      {group: "操作记录", description: "删除操作记录"},
	"DELETE /sysOperationRecord/deleteSysOperationRecordByIds": {group: "操作记录", description: "批量删除操作历史"},
	"DELETE /sysParams/deleteSysParams":                        {group: "参数管理", description: "删除参数"},
	"DELETE /sysParams/deleteSysParamsByIds":                   {group: "参数管理", description: "批量删除参数"},
	"DELETE /sysVersion/deleteSysVersion":                      {group: "版本控制", description: "删除版本"},
	"DELETE /sysVersion/deleteSysVersionByIds":                 {group: "版本控制", description: "批量删除版本"},
	"DELETE /timedTask/deleteTimedTask":                        {group: "定时任务", description: "删除定时任务"},
	"DELETE /user/deleteUser":                                  {group: "系统用户", description: "删除用户"},
	"GET /api/getApiGroups":                                    {group: "api", description: "获取路由组"},
	"GET /api/getApiRoles":                                     {group: "api", description: "获取指定API关联角色列表"},
	"GET /api/syncApi":                                         {group: "api", description: "获取待同步API"},
	"GET /attachmentCategory/getCategoryList":                  {group: "媒体库分类", description: "分类列表"},
	"GET /authority/getDataScopeDepts":                         {group: "角色", description: "获取角色自定义部门集"},
	"GET /authority/getUsersByAuthority":                       {group: "角色", description: "获取角色关联用户ID列表"},
	"GET /department/findDepartment":                           {group: "部门", description: "根据ID获取部门"},
	"GET /department/getDepartmentUsers":                       {group: "部门", description: "获取部门成员ID列表"},
	"GET /info/findInfo":                                       {group: "公告", description: "根据ID获取公告"},
	"GET /info/getInfoList":                                    {group: "公告", description: "获取公告列表"},
	"GET /logViewer/content":                                   {group: "文件日志", description: "分块读取日志文件内容"},
	"GET /logViewer/dates":                                     {group: "文件日志", description: "获取存在日志的日期"},
	"GET /logViewer/files":                                     {group: "文件日志", description: "获取日期下的日志文件"},
	"GET /menu/getMenuRoles":                                   {group: "菜单", description: "获取菜单关联角色列表"},
	"GET /position/findPosition":                               {group: "岗位", description: "根据ID获取岗位"},
	"GET /position/getPositionUsers":                           {group: "岗位", description: "获取岗位成员ID列表"},
	"GET /integration/configs/:kind":                           {group: "集成配置", description: "按类型获取集成配置"},
	"GET /integration/configs/:kind/:provider":                 {group: "集成配置", description: "获取指定集成配置"},
	"GET /payment/orders":                                      {group: "支付", description: "分页查询支付订单"},
	"GET /payment/orders/:provider/:tradeNo":                   {group: "支付", description: "按路径查询支付订单"},
	"POST /payment/create":                                     {group: "支付", description: "创建支付订单"},
	"POST /payment/query":                                      {group: "支付", description: "同步支付订单状态"},
	"POST /payment/refund":                                     {group: "支付", description: "申请支付订单退款"},
	"POST /payment/orders/:provider/:tradeNo/refund":           {group: "支付", description: "按路径申请支付订单退款"},
	"POST /payment/fulfill":                                    {group: "支付", description: "重试支付订单发货"},
	"POST /payment/orders/:provider/:tradeNo/fulfill":          {group: "支付", description: "按路径重试支付订单发货"},
	"POST /payment/providers/:provider/test":                   {group: "支付", description: "测试支付渠道配置与沙箱交易链路"},
	"GET /securityConfig/getSecurityConfig":                    {group: "安全配置", description: "获取安全配置"},
	"GET /sysDictionary/exportSysDictionary":                   {group: "系统字典", description: "导出字典JSON"},
	"GET /sysDictionary/findSysDictionary":                     {group: "系统字典", description: "根据ID获取字典（建议选择）"},
	"GET /sysDictionary/getSysDictionaryList":                  {group: "系统字典", description: "获取字典列表"},
	"GET /sysDictionary/getSysDictionaryListWithDetails":       {group: "系统字典", description: "获取字典列表(含明细)"},
	"GET /sysDictionaryDetail/findSysDictionaryDetail":         {group: "系统字典详情", description: "根据ID获取字典内容"},
	"GET /sysDictionaryDetail/getDictionaryDetailsByParent":    {group: "系统字典详情", description: "根据父级ID获取字典详情"},
	"GET /sysDictionaryDetail/getDictionaryPath":               {group: "系统字典详情", description: "获取字典详情的完整路径"},
	"GET /sysDictionaryDetail/getDictionaryTreeList":           {group: "系统字典详情", description: "获取字典数列表"},
	"GET /sysDictionaryDetail/getDictionaryTreeListByType":     {group: "系统字典详情", description: "根据分类获取字典数列表"},
	"GET /sysDictionaryDetail/getSysDictionaryDetailList":      {group: "系统字典详情", description: "获取字典内容列表"},
	"GET /sysError/findSysError":                               {group: "错误日志", description: "根据ID获取错误日志"},
	"GET /sysError/getSysErrorList":                            {group: "错误日志", description: "获取错误日志列表"},
	"GET /sysExportTemplate/exportExcel":                       {group: "导出模板", description: "导出Excel"},
	"GET /sysExportTemplate/exportTemplate":                    {group: "导出模板", description: "下载模板"},
	"GET /sysExportTemplate/findSysExportTemplate":             {group: "导出模板", description: "根据ID获取导出模板"},
	"GET /sysExportTemplate/getSysExportTemplateList":          {group: "导出模板", description: "获取导出模板列表"},
	"GET /sysExportTemplate/previewSQL":                        {group: "导出模板", description: "预览SQL"},
	"GET /sysLoginLog/findLoginLog":                            {group: "登录日志", description: "根据ID获取登录日志"},
	"GET /sysLoginLog/getLoginLogList":                         {group: "登录日志", description: "获取登录日志列表"},
	"GET /sysOperationRecord/findSysOperationRecord":           {group: "操作记录", description: "根据ID获取操作记录"},
	"GET /sysOperationRecord/getSysOperationRecordList":        {group: "操作记录", description: "获取操作记录列表"},
	"GET /sysParams/findSysParams":                             {group: "参数管理", description: "根据ID获取参数"},
	"GET /sysParams/getSysParam":                               {group: "参数管理", description: "获取参数列表"},
	"GET /sysParams/getSysParamsList":                          {group: "参数管理", description: "获取参数列表"},
	"GET /sysVersion/downloadVersionJson":                      {group: "版本控制", description: "下载版本json"},
	"GET /sysVersion/findSysVersion":                           {group: "版本控制", description: "获取单一版本"},
	"GET /sysVersion/getSysVersionList":                        {group: "版本控制", description: "获取版本列表"},
	"GET /timedTask/alertStream":                               {group: "定时任务", description: "订阅定时任务失败告警(SSE)"},
	"GET /timedTask/getRegisteredMethods":                      {group: "定时任务", description: "获取已注册方法列表"},
	"GET /timedTask/getTimedTaskList":                          {group: "定时任务", description: "获取定时任务列表"},
	"GET /timedTask/getTimedTaskLogList":                       {group: "定时任务", description: "获取定时任务执行日志"},
	"GET /user/getUserInfo":                                    {group: "系统用户", description: "获取自身信息(必选)"},
	"POST /api/createApi":                                      {group: "api", description: "创建api"},
	"POST /api/deleteApi":                                      {group: "api", description: "删除Api"},
	"POST /api/enterSyncApi":                                   {group: "api", description: "确认同步API"},
	"POST /api/getAllApis":                                     {group: "api", description: "获取所有api"},
	"POST /api/getApiById":                                     {group: "api", description: "获取api详细信息"},
	"POST /api/getApiList":                                     {group: "api", description: "获取api列表"},
	"POST /api/ignoreApi":                                      {group: "api", description: "忽略API"},
	"POST /api/setApiRoles":                                    {group: "api", description: "全量覆盖API关联角色列表"},
	"POST /api/updateApi":                                      {group: "api", description: "更新Api"},
	"POST /attachmentCategory/addCategory":                     {group: "媒体库分类", description: "添加/编辑分类"},
	"POST /attachmentCategory/deleteCategory":                  {group: "媒体库分类", description: "删除分类"},
	"POST /authority/copyAuthority":                            {group: "角色", description: "拷贝角色"},
	"POST /authority/createAuthority":                          {group: "角色", description: "创建角色"},
	"POST /authority/deleteAuthority":                          {group: "角色", description: "删除角色"},
	"POST /authority/getAuthorityList":                         {group: "角色", description: "获取角色列表"},
	"POST /authority/setDataScope":                             {group: "角色", description: "设置角色数据权限"},
	"POST /authority/setRoleUsers":                             {group: "角色", description: "全量覆盖角色关联用户"},
	"POST /authorityBtn/canRemoveAuthorityBtn":                 {group: "按钮权限", description: "删除按钮"},
	"POST /authorityBtn/getAuthorityBtn":                       {group: "按钮权限", description: "获取已有按钮权限"},
	"POST /authorityBtn/setAuthorityBtn":                       {group: "按钮权限", description: "设置按钮权限"},
	"POST /casbin/getPolicyPathByAuthorityId":                  {group: "casbin", description: "获取权限列表"},
	"POST /casbin/updateCasbin":                                {group: "casbin", description: "更改角色api权限"},
	"POST /dataAccessLog/getDataAccessLogList":                 {group: "数据权限审计", description: "获取数据权限审计日志"},
	"POST /department/createDepartment":                        {group: "部门", description: "创建部门"},
	"POST /department/getDepartmentList":                       {group: "部门", description: "获取部门树"},
	"POST /department/setDepartmentUsers":                      {group: "部门", description: "设置部门成员(反向分配)"},
	"POST /email/emailTest":                                    {group: "email", description: "发送测试邮件"},
	"POST /email/sendEmail":                                    {group: "email", description: "发送邮件"},
	"POST /fileUploadAndDownload/deleteFile":                   {group: "文件上传与下载", description: "删除文件"},
	"POST /fileUploadAndDownload/editFileName":                 {group: "文件上传与下载", description: "文件名或者备注编辑"},
	"POST /fileUploadAndDownload/getFileList":                  {group: "文件上传与下载", description: "获取上传文件列表"},
	"POST /fileUploadAndDownload/importURL":                    {group: "文件上传与下载", description: "导入URL"},
	"POST /fileUploadAndDownload/upload":                       {group: "文件上传与下载", description: "文件上传（建议选择）"},
	"POST /info/createInfo":                                    {group: "公告", description: "新建公告"},
	"POST /jwt/jsonInBlacklist":                                {group: "jwt", description: "jwt加入黑名单(退出，必选)"},
	"POST /mediaUpload/chunk":                                  {group: "媒体上传", description: "上传分片"},
	"POST /mediaUpload/complete":                               {group: "媒体上传", description: "完成大文件上传"},
	"POST /mediaUpload/init":                                   {group: "媒体上传", description: "初始化大文件上传"},
	"POST /menu/addBaseMenu":                                   {group: "菜单", description: "新增菜单"},
	"POST /menu/addMenuAuthority":                              {group: "菜单", description: "增加menu和角色关联关系"},
	"POST /menu/deleteBaseMenu":                                {group: "菜单", description: "删除菜单"},
	"POST /menu/getBaseMenuById":                               {group: "菜单", description: "根据id获取菜单"},
	"POST /menu/getBaseMenuTree":                               {group: "菜单", description: "获取用户动态路由"},
	"POST /menu/getMenu":                                       {group: "菜单", description: "获取菜单树(必选)"},
	"POST /menu/getMenuAuthority":                              {group: "菜单", description: "获取指定角色menu"},
	"POST /menu/getMenuList":                                   {group: "菜单", description: "分页获取基础menu列表"},
	"POST /menu/setMenuRoles":                                  {group: "菜单", description: "全量覆盖菜单关联角色列表"},
	"POST /menu/updateBaseMenu":                                {group: "菜单", description: "更新菜单"},
	"PUT /integration/configs/:kind/:provider":                 {group: "集成配置", description: "保存集成配置"},
	"DELETE /integration/configs/:kind/:provider":              {group: "集成配置", description: "删除集成配置"},
	"POST /payment/order":                                      {group: "支付", description: "查询支付订单"},
	"POST /position/createPosition":                            {group: "岗位", description: "创建岗位"},
	"POST /position/getPositionList":                           {group: "岗位", description: "获取岗位列表"},
	"POST /position/setPositionUsers":                          {group: "岗位", description: "设置岗位成员(反向分配)"},
	"POST /securityConfig/setSecurityConfig":                   {group: "安全配置", description: "设置安全配置"},
	"POST /sysApiToken/createApiToken":                         {group: "API Token", description: "签发API Token"},
	"POST /sysApiToken/deleteApiToken":                         {group: "API Token", description: "作废API Token"},
	"POST /sysApiToken/getApiTokenList":                        {group: "API Token", description: "获取API Token列表"},
	"POST /sysDictionary/createSysDictionary":                  {group: "系统字典", description: "新增字典"},
	"POST /sysDictionary/importSysDictionary":                  {group: "系统字典", description: "导入字典JSON"},
	"POST /sysDictionaryDetail/createSysDictionaryDetail":      {group: "系统字典详情", description: "新增字典内容"},
	"POST /sysError/createSysError":                            {group: "错误日志", description: "新建错误日志"},
	"POST /sysExportTemplate/createSysExportTemplate":          {group: "导出模板", description: "新增导出模板"},
	"POST /sysExportTemplate/importExcel":                      {group: "导出模板", description: "导入Excel"},
	"POST /sysOperationRecord/createSysOperationRecord":        {group: "操作记录", description: "新增操作记录"},
	"POST /sysParams/createSysParams":                          {group: "参数管理", description: "新建参数"},
	"POST /system/getServerInfo":                               {group: "系统服务", description: "获取服务器信息"},
	"POST /system/getSystemConfig":                             {group: "系统服务", description: "获取配置文件内容"},
	"POST /system/setSystemConfig":                             {group: "系统服务", description: "设置配置文件内容"},
	"POST /sysVersion/exportVersion":                           {group: "版本控制", description: "创建版本"},
	"POST /sysVersion/importVersion":                           {group: "版本控制", description: "同步版本"},
	"POST /timedTask/createTimedTask":                          {group: "定时任务", description: "创建定时任务"},
	"POST /timedTask/toggleTimedTask":                          {group: "定时任务", description: "启用/停用定时任务"},
	"POST /timedTask/triggerTimedTask":                         {group: "定时任务", description: "手动触发定时任务"},
	"POST /user/admin_register":                                {group: "系统用户", description: "用户注册"},
	"POST /user/changePassword":                                {group: "系统用户", description: "修改密码（建议选择)"},
	"POST /user/getUserList":                                   {group: "系统用户", description: "获取用户列表"},
	"POST /user/resetPassword":                                 {group: "系统用户", description: "重置用户密码"},
	"POST /user/setUserAuthorities":                            {group: "系统用户", description: "设置权限组"},
	"POST /user/setUserAuthority":                              {group: "系统用户", description: "修改用户角色(必选)"},
	"POST /user/setUserDepartments":                            {group: "系统用户", description: "设置用户归属部门"},
	"POST /user/setUserPositions":                              {group: "系统用户", description: "设置用户岗位"},
	"PUT /authority/updateAuthority":                           {group: "角色", description: "更新角色信息"},
	"PUT /department/updateDepartment":                         {group: "部门", description: "更新部门"},
	"PUT /info/updateInfo":                                     {group: "公告", description: "更新公告"},
	"PUT /position/updatePosition":                             {group: "岗位", description: "更新岗位"},
	"PUT /sysDictionary/updateSysDictionary":                   {group: "系统字典", description: "更新字典"},
	"PUT /sysDictionaryDetail/updateSysDictionaryDetail":       {group: "系统字典详情", description: "更新字典内容"},
	"PUT /sysError/updateSysError":                             {group: "错误日志", description: "更新错误日志"},
	"PUT /sysExportTemplate/updateSysExportTemplate":           {group: "导出模板", description: "更新导出模板"},
	"PUT /sysParams/updateSysParams":                           {group: "参数管理", description: "更新参数"},
	"PUT /timedTask/updateTimedTask":                           {group: "定时任务", description: "更新定时任务"},
	"PUT /user/setSelfInfo":                                    {group: "系统用户", description: "设置自身信息(必选)"},
	"PUT /user/setSelfSetting":                                 {group: "系统用户", description: "用户界面配置"},
	"PUT /user/setUserInfo":                                    {group: "系统用户", description: "设置用户信息"},
}

// Metadata returns the administration group and description for a route.
func RouteMetadata(method, path string) (string, string) {
	if value, ok := apiMetadata[strings.ToUpper(method)+" "+path]; ok {
		return value.group, value.description
	}
	return routeGroup(path), ""
}

func routeGroup(path string) string {
	parts := strings.Split(strings.Trim(path, "/"), "/")
	if len(parts) > 0 && parts[0] != "" {
		return parts[0]
	}
	return "base"
}
