import { cookies } from "next/headers" export type UserRole = "customer" | "plumber" | "admin" export interface User { id: string email: string name: string role: UserRole phone?: string address?: string profileImage?: string isVerified?: boolean specialization?: string // للسباكين experience?: number // للسباكين rating?: number // للسباكين } // Mock users database - في التطبيق الحقيقي سيكون هذا في قاعدة بيانات const users: User[] = [ { id: "1", email: "admin@plumbing.com", name: "مدير النظام", role: "admin", }, { id: "2", email: "customer@example.com", name: "أحمد محمد", role: "customer", phone: "01234567890", address: "القاهرة، مصر", }, { id: "3", email: "plumber@example.com", name: "محمد السباك", role: "plumber", phone: "01987654321", specialization: "سباكة عامة", experience: 5, rating: 4.8, isVerified: true, }, ] export async function authenticate(email: string, password: string): Promise { // في التطبيق الحقيقي، سنتحقق من كلمة المرور المشفرة const user = users.find((u) => u.email === email) if (user && password === "123456") { // كلمة مرور تجريبية return user } return null } export async function register(userData: Omit & { password: string }): Promise { const newUser: User = { ...userData, id: Date.now().toString(), isVerified: userData.role === "customer", // العملاء يتم تفعيلهم تلقائياً } users.push(newUser) return newUser } export async function getCurrentUser(): Promise { const cookieStore = cookies() const userCookie = cookieStore.get("user") if (!userCookie) return null try { const userData = JSON.parse(userCookie.value) return users.find((u) => u.id === userData.id) || null } catch { return null } } export function setUserCookie(user: User) { const cookieStore = cookies() cookieStore.set("user", JSON.stringify({ id: user.id, role: user.role }), { httpOnly: true, secure: process.env.NODE_ENV === "production", sameSite: "lax", maxAge: 60 * 60 * 24 * 7, // أسبوع واحد }) } export function clearUserCookie() { const cookieStore = cookies() cookieStore.delete("user") }