import { z } from "zod";
const teamRoleSchema = z.enum(["owner", "admin", "member", "viewer"]);
const invitationStatusSchema = z.enum(["pending", "accepted", "declined", "expired"]);
const teamSchema = z.object({
  id: z.string().uuid(),
  name: z.string().min(2, "Name must be at least 2 characters").max(100, "Name must be at most 100 characters"),
  slug: z.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, "Slug must contain only lowercase letters, numbers, and hyphens"),
  description: z.string().nullable().optional(),
  ownerId: z.string(),
  avatarUrl: z.string().url().nullable().optional(),
  settings: z.record(z.string(), z.unknown()).default({}),
  createdAt: z.string().datetime(),
  updatedAt: z.string().datetime()
});
const teamMemberSchema = z.object({
  id: z.string().uuid(),
  teamId: z.string(),
  userId: z.string(),
  role: teamRoleSchema,
  invitedBy: z.string().nullable().optional(),
  joinedAt: z.string().datetime(),
  createdAt: z.string().datetime(),
  updatedAt: z.string().datetime()
});
const teamInvitationSchema = z.object({
  id: z.string().uuid(),
  teamId: z.string(),
  email: z.string().email("Invalid email address"),
  role: teamRoleSchema,
  status: invitationStatusSchema,
  token: z.string().uuid(),
  invitedBy: z.string(),
  expiresAt: z.string().datetime(),
  acceptedAt: z.string().datetime().nullable().optional(),
  declinedAt: z.string().datetime().nullable().optional(),
  createdAt: z.string().datetime(),
  updatedAt: z.string().datetime()
});
const createTeamSchema = z.object({
  name: z.string().min(2, "Name must be at least 2 characters").max(100, "Name must be at most 100 characters"),
  slug: z.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/, "Slug must contain only lowercase letters, numbers, and hyphens"),
  description: z.string().optional()
});
const updateTeamSchema = z.object({
  name: z.string().min(2).max(100).optional(),
  slug: z.string().regex(/^[a-z0-9]+(?:-[a-z0-9]+)*$/).optional(),
  description: z.string().nullable().optional(),
  avatarUrl: z.string().url().nullable().optional(),
  settings: z.record(z.string(), z.unknown()).optional()
});
const inviteMemberSchema = z.object({
  email: z.string().email("Invalid email address"),
  role: z.enum(["admin", "member", "viewer"], {
    message: "Role must be admin, member, or viewer"
  })
  // Cannot invite as owner
});
const updateMemberRoleSchema = z.object({
  role: z.enum(["admin", "member", "viewer"], {
    message: "Role must be admin, member, or viewer"
  })
  // Cannot promote to owner
});
const paginationSchema = z.object({
  page: z.coerce.number().int().positive().default(1),
  limit: z.coerce.number().int().positive().max(100).default(20)
});
const teamListQuerySchema = paginationSchema.extend({
  search: z.string().optional(),
  sort: z.enum(["createdAt", "updatedAt", "name"]).default("createdAt"),
  order: z.enum(["asc", "desc"]).default("desc"),
  scope: z.enum(["user", "all"]).default("user")
  // 'all' requires superadmin
});
const memberListQuerySchema = paginationSchema.extend({
  role: teamRoleSchema.optional(),
  search: z.string().optional()
});
const invitationListQuerySchema = paginationSchema.extend({
  status: invitationStatusSchema.optional()
});
export {
  createTeamSchema,
  invitationListQuerySchema,
  invitationStatusSchema,
  inviteMemberSchema,
  memberListQuerySchema,
  paginationSchema,
  teamInvitationSchema,
  teamListQuerySchema,
  teamMemberSchema,
  teamRoleSchema,
  teamSchema,
  updateMemberRoleSchema,
  updateTeamSchema
};
