import { z } from "zod";

import { createApiResponseSchema } from "./Factory";
export interface IAddress {
  street: string;
  city: string;
  state: string;
  postal_code: string;
  country: string;
}

export interface IContactPerson {
  full_name: string;
  first_name: string;
  last_name: string;
  email: string;
  phone: string;
  mobile: string;
  position: string;
  is_primary: boolean;
}

export interface ITags {
  keywords: string[];
  categories: any[];
  specializations: string[];
  certifications: string[];
  cpv_codes: string[];
}

export interface ICreateCompanyCredentials {
  name: string;
  email: string;
  phone: string;
  website: string;
  type: string;
  description: string;
  founded_year: number;
  employee_count: number;
  annual_revenue: number;
  currency: string;
  industry: string;
  language: string;
  tax_id: string;
  registration_number: string;
  timezone: string;
  address: IAddress;
  contact_person?: IContactPerson;
  tags: ITags;
}

export const companySchema = z.object({
  id: z.string(),
  name: z.string(),
  email: z.string().email().optional(),
  phone: z.string().optional(),
  website: z.string(),
  type: z.string(),
  description: z.string(),
  founded_year: z.number(),
  employee_count: z.number(),
  annual_revenue: z.number(),
  currency: z.string(),
  industry: z.string(),
  language: z.string(),
  tax_id: z.string(),
  registration_number: z.string(),
  timezone: z.string(),
  address: z.object({
    street: z.string(),
    city: z.string(),
    state: z.string(),
    postal_code: z.string(),
    country: z.string(),
  }),
  contact_person: z
    .object({
      full_name: z.string(),
      first_name: z.string(),
      last_name: z.string(),
      email: z.string().email(),
      phone: z.string(),
      mobile: z.string(),
      position: z.string(),
      is_primary: z.boolean(),
    })
    .optional(),
  tags: z.object({
    keywords: z.array(z.string()).or(z.null()).optional(),
    categories: z.array(z.any()).or(z.null()).optional(),
    specializations: z.array(z.string()).or(z.null()).optional(),
    certifications: z.array(z.string()).or(z.null()).optional(),
    cpv_codes: z.array(z.string()).or(z.null()).optional(),
  }),
});

export const companiesResponseSchema = z.object({
  companies: z.array(companySchema).or(z.null()),
});

export const companyDetailsApiResponseSchema =
  createApiResponseSchema(companySchema);
export const CompaniesListResponseSchema = createApiResponseSchema(
  companiesResponseSchema,
);
export type TCompany = z.infer<typeof companySchema>;
export type TCompaniesResponse = z.infer<typeof companiesResponseSchema>;
