import { z } from 'zod';
import { PortfolioElement } from './portfolio';
import { PortfolioProjectStatus } from '@prisma/client';
import { AppRouterInstance } from 'next/dist/shared/lib/app-router-context.shared-runtime';
import { ActionButton } from './common';

export const projectFormSchema = z.object({
  title: z.string({ required_error: 'Project title is required' }),
  description: z.string({ required_error: 'Project description is required' }),
  technologies: z.array(z.string()).optional(),
  url: z.string().url('Please enter a valid URL').optional().nullable().or(z.literal('')),
  gitUrl: z.string().url('Please enter a valid URL').optional().nullable().or(z.literal('')),
  image: z.string({ required_error: 'Project image is required.' }).url('Please enter a valid image URL'),
  vercelProjectId: z.string().nullable().optional(),
});

export type ProjectFormValues = z.infer<typeof projectFormSchema>;

export interface ProjectFormProps {
  project?: Project;
  onFieldUpdate?: (field: keyof Project, value: string) => void;
  onSubmit: (project: ProjectFormValues) => void;
  isEditor?: boolean;
  isEdit?: boolean;
  cancelAction: () => void;
  className?: string;
}

export interface ProjectEntryProps {
  project: PortfolioProject | Project;
  actions?: ActionButton[];
  isAuthor?: boolean;
}

export interface ProjectListProps {
  projects: PortfolioProject[];
  updateProjects: (updatedProjects: Project[]) => void;
}
export interface GetProjectActionsProps {
  project: Project;
  router: AppRouterInstance;
  setSelectedProjectId: (projectId: string) => void;
}
export interface AddProjectTabsProps {
  selectedProject: Project | undefined;
  setEditingProject?: (project: PortfolioProject | undefined) => void;
  availableProjects: Project[];
  onProjectSelect: (projectId: string) => void;
  onCancel: () => void;
  defaultTab?: 'existing' | 'new';
  showCancelButton?: boolean;
  refreshProjects: () => void;
  isEditor?: boolean;
  className?: string;
}
export interface ProjectsViewProps {
  title: string;
  isAuthor?: boolean;
  emptyStateMessage?: string;
  emptyStateAction?: string;
}
export interface GetPortfolioProjectActionsProps {
  project: PortfolioProject;
  isAuthor: boolean;
  approveProject: (projectId: string) => void;
  rejectProject: (project: PortfolioProject) => void;
  resubmitProject: (projectId: string) => void;
  editProject: (project: PortfolioProject) => void;
  deleteProject: (project: PortfolioProject) => void;
  onViewDetails: (project: PortfolioProject) => void;
  viewFeedback: (project: PortfolioProject) => void;
}

export interface Project {
  id: string;
  title: string;
  description: string;
  image: string;
  url: string | null;
  gitUrl: string | null;
  technologies: string[];
  vercelProjectId: string | null;
}

export interface PortfolioProject extends Project {
  status: PortfolioProjectStatus | null;
  username: string;
  isOwner: boolean;
  message?: string;
}

export interface ProjectCardsProps {
  projects: PortfolioProject[];
  styling?: PortfolioElement['styling'];
  sectionId?: string;
  isPublished?: boolean;
}
