import { z } from "zod";
import { createApiResponseSchema } from "./Factory";

const customersSchema = z.object({
  role: z.enum(["admin", "analyst"]).optional(),
  companies: z
    .array(
      z.object({
        id: z.string(),
        name: z.string(),
      }),
    )
    .or(z.null())
    .optional(),
  compliance_notes: z.any(),

  created_at: z.number(),

  email: z.string().email(),

  full_name: z.string(),
  id: z.string(),

  phone: z.string(),

  status: z.string(),

  type: z.string(),
  updated_at: z.number(),
  updated_by: z.any(),
  username: z.string(),
});

export const customersListResponse = z.object({
  customers: z.array(customersSchema),
});
const createCustomerCredentials = z.object({
  address: z
    .object({
      address_type: z.string(),
      city: z.string(),
      country: z.string(),
      is_default: z.boolean(),
      postal_code: z.string(),
      state: z.string(),
      street: z.string(),
    })
    .optional(),
  annual_revenue: z.number().min(0).max(999999999999).optional(),
  business_type: z.string().min(2).max(100).optional(),
  companies: z.array(z.string()).optional(),
  contact_person: z
    .object({
      email: z.string(),
      first_name: z.string(),
      full_name: z.string(),
      is_primary: z.boolean(),
      last_name: z.string(),
      phone: z.string(),
      position: z.string(),
    })
    .optional(),
  currency: z
    .enum([
      "USD",
      "EUR",
      "GBP",
      "JPY",
      "CAD",
      "AUD",
      "CHF",
      "CNY",
      "INR",
      "BRL",
    ])
    .optional(),
  email: z.string().email(),
  role: z.enum(["admin", "analyst"]),
  employee_count: z.number().int().min(1).max(100000).optional(),
  first_name: z.string().min(2).max(50).optional(),
  founded_year: z.number().int().min(1800).max(2100).optional(),
  full_name: z.string().min(2).max(100).optional(),
  industry: z.string().min(2).max(100).optional(),
  language: z.enum(["en", "ar", "fr", "es", "de", "zh", "ja", "ko"]).optional(),
  last_name: z.string().min(2).max(50).optional(),

  password: z.string().min(8).max(128),
  phone: z.string().min(10).max(20).optional(),
  registration_number: z.string().min(5).max(50).optional(),
  tax_id: z.string().min(5).max(50).optional(),
  timezone: z.string().min(3).max(50).optional(),
  type: z.string(),
  username: z
    .string()
    .min(3)
    .max(30)
    .regex(
      /^[a-zA-Z0-9]+$/,
      "Username must contain only alphanumeric characters",
    ),
});
const assignCustomerToCompanySchema = z.object({
  company_ids: z.array(z.string()),
});
export const CustomerListResponseSchema = createApiResponseSchema(
  customersListResponse,
);
export type TAssignCustomerToCompanyCredentials = z.infer<
  typeof assignCustomerToCompanySchema
>;
export type TCustomer = z.infer<typeof customersSchema>;
export type CreateCustomerCredentials = z.infer<
  typeof createCustomerCredentials
>;
export type TCustomersListResponse = z.infer<typeof customersListResponse>;
