/*
 * Code generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.
 */

import * as z from "zod/v4-mini";
import { remap as remap$ } from "../../lib/primitives.js";
import { ClosedEnum } from "../../types/enums.js";
import {
  OrganizationCompanyLegalEntitySchema,
  OrganizationCompanyLegalEntitySchema$Outbound,
  OrganizationCompanyLegalEntitySchema$outboundSchema,
} from "./organizationcompanylegalentityschema.js";
import {
  OrganizationCustomerEmailSettings,
  OrganizationCustomerEmailSettings$Outbound,
  OrganizationCustomerEmailSettings$outboundSchema,
} from "./organizationcustomeremailsettings.js";
import {
  OrganizationCustomerPortalSettings,
  OrganizationCustomerPortalSettings$Outbound,
  OrganizationCustomerPortalSettings$outboundSchema,
} from "./organizationcustomerportalsettings.js";
import {
  OrganizationDetails,
  OrganizationDetails$Outbound,
  OrganizationDetails$outboundSchema,
} from "./organizationdetails.js";
import {
  OrganizationFeatureSettingsUpdate,
  OrganizationFeatureSettingsUpdate$Outbound,
  OrganizationFeatureSettingsUpdate$outboundSchema,
} from "./organizationfeaturesettingsupdate.js";
import {
  OrganizationIndividualLegalEntitySchema,
  OrganizationIndividualLegalEntitySchema$Outbound,
  OrganizationIndividualLegalEntitySchema$outboundSchema,
} from "./organizationindividuallegalentityschema.js";
import {
  OrganizationSocialLink,
  OrganizationSocialLink$Outbound,
  OrganizationSocialLink$outboundSchema,
} from "./organizationsociallink.js";
import {
  OrganizationSubscriptionSettings,
  OrganizationSubscriptionSettings$Outbound,
  OrganizationSubscriptionSettings$outboundSchema,
} from "./organizationsubscriptionsettings.js";
import {
  PresentmentCurrency,
  PresentmentCurrency$outboundSchema,
} from "./presentmentcurrency.js";
import {
  TaxBehaviorOption,
  TaxBehaviorOption$outboundSchema,
} from "./taxbehavioroption.js";

export type LegalEntity =
  | OrganizationCompanyLegalEntitySchema
  | OrganizationIndividualLegalEntitySchema;

export const CountryAlpha2Input = {
  Ad: "AD",
  Ae: "AE",
  Af: "AF",
  Ag: "AG",
  Ai: "AI",
  Al: "AL",
  Am: "AM",
  Ao: "AO",
  Aq: "AQ",
  Ar: "AR",
  As: "AS",
  At: "AT",
  Au: "AU",
  Aw: "AW",
  Ax: "AX",
  Az: "AZ",
  Ba: "BA",
  Bb: "BB",
  Bd: "BD",
  Be: "BE",
  Bf: "BF",
  Bg: "BG",
  Bh: "BH",
  Bi: "BI",
  Bj: "BJ",
  Bl: "BL",
  Bm: "BM",
  Bn: "BN",
  Bo: "BO",
  Bq: "BQ",
  Br: "BR",
  Bs: "BS",
  Bt: "BT",
  Bv: "BV",
  Bw: "BW",
  By: "BY",
  Bz: "BZ",
  Ca: "CA",
  Cc: "CC",
  Cd: "CD",
  Cf: "CF",
  Cg: "CG",
  Ch: "CH",
  Ci: "CI",
  Ck: "CK",
  Cl: "CL",
  Cm: "CM",
  Cn: "CN",
  Co: "CO",
  Cr: "CR",
  Cv: "CV",
  Cw: "CW",
  Cx: "CX",
  Cy: "CY",
  Cz: "CZ",
  De: "DE",
  Dj: "DJ",
  Dk: "DK",
  Dm: "DM",
  Do: "DO",
  Dz: "DZ",
  Ec: "EC",
  Ee: "EE",
  Eg: "EG",
  Eh: "EH",
  Er: "ER",
  Es: "ES",
  Et: "ET",
  Fi: "FI",
  Fj: "FJ",
  Fk: "FK",
  Fm: "FM",
  Fo: "FO",
  Fr: "FR",
  Ga: "GA",
  Gb: "GB",
  Gd: "GD",
  Ge: "GE",
  Gf: "GF",
  Gg: "GG",
  Gh: "GH",
  Gi: "GI",
  Gl: "GL",
  Gm: "GM",
  Gn: "GN",
  Gp: "GP",
  Gq: "GQ",
  Gr: "GR",
  Gs: "GS",
  Gt: "GT",
  Gu: "GU",
  Gw: "GW",
  Gy: "GY",
  Hk: "HK",
  Hm: "HM",
  Hn: "HN",
  Hr: "HR",
  Ht: "HT",
  Hu: "HU",
  Id: "ID",
  Ie: "IE",
  Il: "IL",
  Im: "IM",
  In: "IN",
  Io: "IO",
  Iq: "IQ",
  Is: "IS",
  It: "IT",
  Je: "JE",
  Jm: "JM",
  Jo: "JO",
  Jp: "JP",
  Ke: "KE",
  Kg: "KG",
  Kh: "KH",
  Ki: "KI",
  Km: "KM",
  Kn: "KN",
  Kr: "KR",
  Kw: "KW",
  Ky: "KY",
  Kz: "KZ",
  La: "LA",
  Lb: "LB",
  Lc: "LC",
  Li: "LI",
  Lk: "LK",
  Lr: "LR",
  Ls: "LS",
  Lt: "LT",
  Lu: "LU",
  Lv: "LV",
  Ly: "LY",
  Ma: "MA",
  Mc: "MC",
  Md: "MD",
  Me: "ME",
  Mf: "MF",
  Mg: "MG",
  Mh: "MH",
  Mk: "MK",
  Ml: "ML",
  Mm: "MM",
  Mn: "MN",
  Mo: "MO",
  Mp: "MP",
  Mq: "MQ",
  Mr: "MR",
  Ms: "MS",
  Mt: "MT",
  Mu: "MU",
  Mv: "MV",
  Mw: "MW",
  Mx: "MX",
  My: "MY",
  Mz: "MZ",
  Na: "NA",
  Nc: "NC",
  Ne: "NE",
  Nf: "NF",
  Ng: "NG",
  Ni: "NI",
  Nl: "NL",
  No: "NO",
  Np: "NP",
  Nr: "NR",
  Nu: "NU",
  Nz: "NZ",
  Om: "OM",
  Pa: "PA",
  Pe: "PE",
  Pf: "PF",
  Pg: "PG",
  Ph: "PH",
  Pk: "PK",
  Pl: "PL",
  Pm: "PM",
  Pn: "PN",
  Pr: "PR",
  Ps: "PS",
  Pt: "PT",
  Pw: "PW",
  Py: "PY",
  Qa: "QA",
  Re: "RE",
  Ro: "RO",
  Rs: "RS",
  Rw: "RW",
  Sa: "SA",
  Sb: "SB",
  Sc: "SC",
  Sd: "SD",
  Se: "SE",
  Sg: "SG",
  Sh: "SH",
  Si: "SI",
  Sj: "SJ",
  Sk: "SK",
  Sl: "SL",
  Sm: "SM",
  Sn: "SN",
  So: "SO",
  Sr: "SR",
  Ss: "SS",
  St: "ST",
  Sv: "SV",
  Sx: "SX",
  Sz: "SZ",
  Tc: "TC",
  Td: "TD",
  Tf: "TF",
  Tg: "TG",
  Th: "TH",
  Tj: "TJ",
  Tk: "TK",
  Tl: "TL",
  Tm: "TM",
  Tn: "TN",
  To: "TO",
  Tr: "TR",
  Tt: "TT",
  Tv: "TV",
  Tw: "TW",
  Tz: "TZ",
  Ua: "UA",
  Ug: "UG",
  Um: "UM",
  Us: "US",
  Uy: "UY",
  Uz: "UZ",
  Va: "VA",
  Vc: "VC",
  Ve: "VE",
  Vg: "VG",
  Vi: "VI",
  Vn: "VN",
  Vu: "VU",
  Wf: "WF",
  Ws: "WS",
  Ye: "YE",
  Yt: "YT",
  Za: "ZA",
  Zm: "ZM",
  Zw: "ZW",
} as const;
export type CountryAlpha2Input = ClosedEnum<typeof CountryAlpha2Input>;

export type OrganizationCreate = {
  name: string;
  slug: string;
  avatarUrl?: string | null | undefined;
  legalEntity?:
    | OrganizationCompanyLegalEntitySchema
    | OrganizationIndividualLegalEntitySchema
    | null
    | undefined;
  /**
   * Public support email.
   */
  email?: string | null | undefined;
  /**
   * Official website of the organization.
   */
  website?: string | null | undefined;
  /**
   * Link to social profiles.
   */
  socials?: Array<OrganizationSocialLink> | null | undefined;
  /**
   * Additional, private, business details Polar needs about active organizations for compliance (KYC).
   */
  details?: OrganizationDetails | null | undefined;
  /**
   * Two-letter country code (ISO 3166-1 alpha-2).
   */
  country?: CountryAlpha2Input | null | undefined;
  featureSettings?: OrganizationFeatureSettingsUpdate | null | undefined;
  subscriptionSettings?: OrganizationSubscriptionSettings | null | undefined;
  customerEmailSettings?: OrganizationCustomerEmailSettings | null | undefined;
  customerPortalSettings?:
    | OrganizationCustomerPortalSettings
    | null
    | undefined;
  defaultPresentmentCurrency?: PresentmentCurrency | undefined;
  defaultTaxBehavior?: TaxBehaviorOption | undefined;
};

/** @internal */
export type LegalEntity$Outbound =
  | OrganizationCompanyLegalEntitySchema$Outbound
  | OrganizationIndividualLegalEntitySchema$Outbound;

/** @internal */
export const LegalEntity$outboundSchema: z.ZodMiniType<
  LegalEntity$Outbound,
  LegalEntity
> = z.union([
  OrganizationCompanyLegalEntitySchema$outboundSchema,
  OrganizationIndividualLegalEntitySchema$outboundSchema,
]);

export function legalEntityToJSON(legalEntity: LegalEntity): string {
  return JSON.stringify(LegalEntity$outboundSchema.parse(legalEntity));
}

/** @internal */
export const CountryAlpha2Input$outboundSchema: z.ZodMiniEnum<
  typeof CountryAlpha2Input
> = z.enum(CountryAlpha2Input);

/** @internal */
export type OrganizationCreate$Outbound = {
  name: string;
  slug: string;
  avatar_url?: string | null | undefined;
  legal_entity?:
    | OrganizationCompanyLegalEntitySchema$Outbound
    | OrganizationIndividualLegalEntitySchema$Outbound
    | null
    | undefined;
  email?: string | null | undefined;
  website?: string | null | undefined;
  socials?: Array<OrganizationSocialLink$Outbound> | null | undefined;
  details?: OrganizationDetails$Outbound | null | undefined;
  country?: string | null | undefined;
  feature_settings?:
    | OrganizationFeatureSettingsUpdate$Outbound
    | null
    | undefined;
  subscription_settings?:
    | OrganizationSubscriptionSettings$Outbound
    | null
    | undefined;
  customer_email_settings?:
    | OrganizationCustomerEmailSettings$Outbound
    | null
    | undefined;
  customer_portal_settings?:
    | OrganizationCustomerPortalSettings$Outbound
    | null
    | undefined;
  default_presentment_currency?: string | undefined;
  default_tax_behavior?: string | undefined;
};

/** @internal */
export const OrganizationCreate$outboundSchema: z.ZodMiniType<
  OrganizationCreate$Outbound,
  OrganizationCreate
> = z.pipe(
  z.object({
    name: z.string(),
    slug: z.string(),
    avatarUrl: z.optional(z.nullable(z.string())),
    legalEntity: z.optional(
      z.nullable(
        z.union([
          OrganizationCompanyLegalEntitySchema$outboundSchema,
          OrganizationIndividualLegalEntitySchema$outboundSchema,
        ]),
      ),
    ),
    email: z.optional(z.nullable(z.string())),
    website: z.optional(z.nullable(z.string())),
    socials: z.optional(
      z.nullable(z.array(OrganizationSocialLink$outboundSchema)),
    ),
    details: z.optional(z.nullable(OrganizationDetails$outboundSchema)),
    country: z.optional(z.nullable(CountryAlpha2Input$outboundSchema)),
    featureSettings: z.optional(
      z.nullable(OrganizationFeatureSettingsUpdate$outboundSchema),
    ),
    subscriptionSettings: z.optional(
      z.nullable(OrganizationSubscriptionSettings$outboundSchema),
    ),
    customerEmailSettings: z.optional(
      z.nullable(OrganizationCustomerEmailSettings$outboundSchema),
    ),
    customerPortalSettings: z.optional(
      z.nullable(OrganizationCustomerPortalSettings$outboundSchema),
    ),
    defaultPresentmentCurrency: z.optional(PresentmentCurrency$outboundSchema),
    defaultTaxBehavior: z.optional(TaxBehaviorOption$outboundSchema),
  }),
  z.transform((v) => {
    return remap$(v, {
      avatarUrl: "avatar_url",
      legalEntity: "legal_entity",
      featureSettings: "feature_settings",
      subscriptionSettings: "subscription_settings",
      customerEmailSettings: "customer_email_settings",
      customerPortalSettings: "customer_portal_settings",
      defaultPresentmentCurrency: "default_presentment_currency",
      defaultTaxBehavior: "default_tax_behavior",
    });
  }),
);

export function organizationCreateToJSON(
  organizationCreate: OrganizationCreate,
): string {
  return JSON.stringify(
    OrganizationCreate$outboundSchema.parse(organizationCreate),
  );
}
