package utils

import (
	"strings"
)

// GetOperationAction 根据路径和方法生成友好的中文操作描述
func GetOperationAction(path, method string) string {
	// 统一转换为小写以便匹配
	pathLower := strings.ToLower(path)
	methodUpper := strings.ToUpper(method)

	// 用户管理
	if strings.Contains(pathLower, "/api/admin/users") {
		if methodUpper == "GET" {
			if strings.Contains(pathLower, "/users/") && !strings.HasSuffix(pathLower, "/users") {
				return "查看用户详情"
			}
			return "查看用户列表"
		}
		if methodUpper == "POST" {
			return "创建用户"
		}
		if methodUpper == "PUT" {
			return "更新用户"
		}
		if methodUpper == "DELETE" {
			return "删除用户"
		}
	}

	// 角色管理
	if strings.Contains(pathLower, "/api/admin/roles") {
		if methodUpper == "GET" {
			if strings.Contains(pathLower, "/permissions") {
				return "查看权限列表"
			}
			return "查看角色列表"
		}
		if methodUpper == "POST" {
			return "创建角色"
		}
		if methodUpper == "PUT" {
			if strings.Contains(pathLower, "/permissions") {
				return "更新角色权限"
			}
			return "更新角色"
		}
		if methodUpper == "DELETE" {
			return "删除角色"
		}
	}

	// 文章管理
	if strings.Contains(pathLower, "/api/admin/posts") {
		if methodUpper == "GET" {
			if strings.Contains(pathLower, "/history") {
				return "查看文章历史"
			}
			if strings.Contains(pathLower, "/access-logs") {
				return "查看文章访问日志"
			}
			return "查看文章列表"
		}
		if methodUpper == "POST" {
			return "创建文章"
		}
		if methodUpper == "PUT" {
			return "更新文章"
		}
		if methodUpper == "PATCH" {
			if strings.Contains(pathLower, "/status") {
				return "切换文章状态"
			}
			return "更新文章"
		}
		if methodUpper == "DELETE" {
			return "删除文章"
		}
	}

	// 分类管理
	if strings.Contains(pathLower, "/api/admin/categories") {
		if methodUpper == "GET" {
			return "查看分类列表"
		}
		if methodUpper == "POST" {
			return "创建分类"
		}
		if methodUpper == "PUT" {
			return "更新分类"
		}
		if methodUpper == "DELETE" {
			return "删除分类"
		}
	}

	// 专栏管理
	if strings.Contains(pathLower, "/api/admin/columns") {
		if methodUpper == "GET" {
			return "查看专栏列表"
		}
		if methodUpper == "POST" {
			if strings.Contains(pathLower, "/posts") {
				return "添加文章到专栏"
			}
			return "创建专栏"
		}
		if methodUpper == "PUT" {
			return "更新专栏"
		}
		if methodUpper == "DELETE" {
			if strings.Contains(pathLower, "/posts/") {
				return "从专栏移除文章"
			}
			return "删除专栏"
		}
	}

	// 标签管理
	if strings.Contains(pathLower, "/api/admin/tags") {
		if methodUpper == "GET" {
			return "查看标签列表"
		}
		if methodUpper == "POST" {
			return "创建标签"
		}
		if methodUpper == "PUT" {
			return "更新标签"
		}
		if methodUpper == "DELETE" {
			return "删除标签"
		}
	}

	// 代码类型管理
	if strings.Contains(pathLower, "/api/admin/code-types") {
		if methodUpper == "GET" {
			return "查看代码类型列表"
		}
		if methodUpper == "POST" {
			return "创建代码类型"
		}
		if methodUpper == "PUT" {
			return "更新代码类型"
		}
		if methodUpper == "DELETE" {
			return "删除代码类型"
		}
	}

	// 代码片段管理
	if strings.Contains(pathLower, "/api/admin/snippets") {
		if methodUpper == "GET" {
			return "查看代码片段列表"
		}
		if methodUpper == "POST" {
			return "创建代码片段"
		}
		if methodUpper == "PUT" {
			return "更新代码片段"
		}
		if methodUpper == "DELETE" {
			return "删除代码片段"
		}
	}

	// 作品管理
	if strings.Contains(pathLower, "/api/admin/works") {
		if methodUpper == "GET" {
			return "查看作品列表"
		}
		if methodUpper == "POST" {
			return "创建作品"
		}
		if methodUpper == "PUT" {
			return "更新作品"
		}
		if methodUpper == "DELETE" {
			return "删除作品"
		}
	}

	// 系统设置管理
	if strings.Contains(pathLower, "/api/admin/settings") {
		if methodUpper == "GET" {
			return "查看系统设置"
		}
		if methodUpper == "POST" {
			return "创建系统设置"
		}
		if methodUpper == "PUT" {
			return "更新系统设置"
		}
		if methodUpper == "DELETE" {
			return "删除系统设置"
		}
	}

	// 关于页面管理
	if strings.Contains(pathLower, "/api/admin/about") {
		if methodUpper == "GET" {
			return "查看关于页面"
		}
		if methodUpper == "POST" {
			return "创建关于页面"
		}
		if methodUpper == "PUT" {
			return "更新关于页面"
		}
		if methodUpper == "DELETE" {
			return "删除关于页面"
		}
	}

	// 客户评价管理
	if strings.Contains(pathLower, "/api/admin/testimonials") {
		if methodUpper == "POST" {
			return "创建客户评价"
		}
		if methodUpper == "PUT" {
			return "更新客户评价"
		}
		if methodUpper == "DELETE" {
			return "删除客户评价"
		}
	}

	// 合作伙伴管理
	if strings.Contains(pathLower, "/api/admin/partners") {
		if methodUpper == "POST" {
			return "创建合作伙伴"
		}
		if methodUpper == "PUT" {
			return "更新合作伙伴"
		}
		if methodUpper == "DELETE" {
			return "删除合作伙伴"
		}
	}

	// 咨询管理
	if strings.Contains(pathLower, "/api/admin/inquiries") {
		if methodUpper == "GET" {
			return "查看咨询列表"
		}
		if methodUpper == "PUT" {
			if strings.Contains(pathLower, "/status") {
				return "更新咨询状态"
			}
			return "更新咨询"
		}
	}

	// 邮箱后缀配置
	if strings.Contains(pathLower, "/api/admin/email-suffixes") {
		if methodUpper == "GET" {
			return "查看邮箱后缀列表"
		}
		if methodUpper == "POST" {
			return "创建邮箱后缀"
		}
		if methodUpper == "PUT" {
			return "更新邮箱后缀"
		}
		if methodUpper == "DELETE" {
			return "删除邮箱后缀"
		}
	}

	// 搜索记录管理
	if strings.Contains(pathLower, "/api/admin/search-logs") {
		if methodUpper == "GET" {
			return "查看搜索记录列表"
		}
		if methodUpper == "DELETE" {
			return "删除搜索记录"
		}
	}

	// 附件管理
	if strings.Contains(pathLower, "/api/admin/attachments") {
		if methodUpper == "GET" {
			return "查看附件列表"
		}
		if methodUpper == "POST" {
			if strings.Contains(pathLower, "/upload") {
				return "上传附件"
			}
			return "创建附件"
		}
		if methodUpper == "PUT" {
			return "更新附件"
		}
		if methodUpper == "DELETE" {
			return "删除附件"
		}
	}

	// 附件分类管理
	if strings.Contains(pathLower, "/api/admin/attachment-categories") {
		if methodUpper == "GET" {
			return "查看附件分类列表"
		}
		if methodUpper == "POST" {
			return "创建附件分类"
		}
		if methodUpper == "PUT" {
			return "更新附件分类"
		}
		if methodUpper == "DELETE" {
			return "删除附件分类"
		}
	}

	// OSS配置管理
	if strings.Contains(pathLower, "/api/admin/oss-configs") {
		if methodUpper == "GET" {
			return "查看OSS配置列表"
		}
		if methodUpper == "POST" {
			return "创建OSS配置"
		}
		if methodUpper == "PUT" {
			return "更新OSS配置"
		}
		if methodUpper == "DELETE" {
			return "删除OSS配置"
		}
	}

	// 操作日志管理
	if strings.Contains(pathLower, "/api/admin/operation-logs") {
		if methodUpper == "GET" {
			return "查看操作日志"
		}
	}

	// 访问日志管理
	if strings.Contains(pathLower, "/api/admin/access-logs") {
		if methodUpper == "GET" {
			return "查看访问日志"
		}
	}

	// 仪表盘
	if strings.Contains(pathLower, "/api/admin/dashboard") {
		if methodUpper == "GET" {
			if strings.Contains(pathLower, "/stats") {
				return "查看仪表盘统计"
			}
			if strings.Contains(pathLower, "/activities") {
				return "查看最近活动"
			}
			return "查看仪表盘"
		}
	}

	// 如果无法匹配，返回原始路径和方法作为后备
	return methodUpper + " " + path
}
