import { z } from 'zod';
import { GetProjectsFramework, GetProjectsProjects } from '@vercel/sdk/models/getprojectsop.js';

export const deploymentFormSchema = z.object({
  name: z
    .string()
    .min(1, 'Name is required')
    .max(100)
    .regex(/^[a-z0-9._-]+$/i, 'Portfolio name can only include lowercase letters, digits, ".", "_", and "-"'),
  framework: z
    .enum(Object.values(GetProjectsFramework) as [string, ...string[]])
    .optional()
    .nullable(),
  rootDirectory: z.string().optional().nullable(),
  buildCommand: z.string().optional().nullable(),
  outputDirectory: z.string().optional().nullable(),
  installCommand: z.string().optional().nullable(),
  env: z
    .array(
      z.object({
        key: z.string(),
        value: z.string(),
      })
    )
    .optional(),
  gitRepository: z.object({
    repo: z.string(),
    type: z.string(),
    id: z.number().nullable(),
    ref: z.string(),
  }),
});

export type DeploymentFormValues = z.infer<typeof deploymentFormSchema>;

export interface DeploymentFormProps {
  onSubmit: (values: Partial<DeploymentFormValues>) => Promise<void>;
  isDeploying: boolean;
  isDisabled: boolean;
  isEdit?: boolean;
  defaultValues?: Partial<DeploymentFormValues>;
}
export interface VercelProjectProps {
  project: GetProjectsProjects;
}

export type DeploymentEvent = {
  date: number;
  id: string;
  text: string;
  type: 'stdout' | 'stderr';
};

export interface DeploymentStatus {
  message: string;
  status: 'READY' | 'ERROR' | 'CANCELLED' | 'BUILDING' | 'INITIALIZING' | 'QUEUED';
  url: string | null;
}

export interface Repository {
  id: string;
  name: string;
  namespace: string;
  url: string;
  defaultBranch: string;
  ownerType: string;
  provider: 'github' | 'gitlab' | 'bitbucket';
  owner: {
    id: string;
    name: string;
  };
  private: boolean;
  slug: string;
}
