/*
 * 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 { safeParse } from "../../lib/schemas.js";
import * as openEnums from "../../types/enums.js";
import { OpenEnum } from "../../types/enums.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import {
  OrganizationCapabilities,
  OrganizationCapabilities$inboundSchema,
  OrganizationCapabilities$Outbound,
  OrganizationCapabilities$outboundSchema,
} from "./organizationcapabilities.js";
import {
  OrganizationCustomerEmailSettings,
  OrganizationCustomerEmailSettings$inboundSchema,
  OrganizationCustomerEmailSettings$Outbound,
  OrganizationCustomerEmailSettings$outboundSchema,
} from "./organizationcustomeremailsettings.js";
import {
  OrganizationCustomerPortalSettings,
  OrganizationCustomerPortalSettings$inboundSchema,
  OrganizationCustomerPortalSettings$Outbound,
  OrganizationCustomerPortalSettings$outboundSchema,
} from "./organizationcustomerportalsettings.js";
import {
  OrganizationFeatureSettings,
  OrganizationFeatureSettings$inboundSchema,
  OrganizationFeatureSettings$Outbound,
  OrganizationFeatureSettings$outboundSchema,
} from "./organizationfeaturesettings.js";
import {
  OrganizationSocialLink,
  OrganizationSocialLink$inboundSchema,
  OrganizationSocialLink$Outbound,
  OrganizationSocialLink$outboundSchema,
} from "./organizationsociallink.js";
import {
  OrganizationStatus,
  OrganizationStatus$inboundSchema,
  OrganizationStatus$outboundSchema,
} from "./organizationstatus.js";
import {
  OrganizationSubscriptionSettings,
  OrganizationSubscriptionSettings$inboundSchema,
  OrganizationSubscriptionSettings$Outbound,
  OrganizationSubscriptionSettings$outboundSchema,
} from "./organizationsubscriptionsettings.js";
import {
  SubscriptionProrationBehavior,
  SubscriptionProrationBehavior$inboundSchema,
  SubscriptionProrationBehavior$outboundSchema,
} from "./subscriptionprorationbehavior.js";
import {
  TaxBehaviorOption,
  TaxBehaviorOption$inboundSchema,
  TaxBehaviorOption$outboundSchema,
} from "./taxbehavioroption.js";

export const CountryAlpha2 = {
  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",
  Cu: "CU",
  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",
  Ir: "IR",
  Is: "IS",
  It: "IT",
  Je: "JE",
  Jm: "JM",
  Jo: "JO",
  Jp: "JP",
  Ke: "KE",
  Kg: "KG",
  Kh: "KH",
  Ki: "KI",
  Km: "KM",
  Kn: "KN",
  Kp: "KP",
  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",
  Ru: "RU",
  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",
  Sy: "SY",
  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 CountryAlpha2 = OpenEnum<typeof CountryAlpha2>;

export type Organization = {
  /**
   * Creation timestamp of the object.
   */
  createdAt: Date;
  /**
   * Last modification timestamp of the object.
   */
  modifiedAt: Date | null;
  /**
   * The ID of the object.
   */
  id: string;
  /**
   * Organization name shown in checkout, customer portal, emails etc.
   */
  name: string;
  /**
   * Unique organization slug in checkout, customer portal and credit card statements.
   */
  slug: string;
  /**
   * Avatar URL shown in checkout, customer portal, emails etc.
   */
  avatarUrl: string | null;
  prorationBehavior: SubscriptionProrationBehavior;
  /**
   * Whether customers can update their subscriptions from the customer portal.
   */
  allowCustomerUpdates: boolean;
  /**
   * Public support email.
   */
  email: string | null;
  /**
   * Official website of the organization.
   */
  website: string | null;
  /**
   * Links to social profiles.
   */
  socials: Array<OrganizationSocialLink>;
  status: OrganizationStatus;
  /**
   * When the business details were submitted for review.
   */
  detailsSubmittedAt: Date | null;
  /**
   * Whether members must access this organization through its SSO connection.
   */
  ssoEnforced: boolean;
  /**
   * Default presentment currency. Used as fallback in checkout and customer portal, if the customer's local currency is not available.
   */
  defaultPresentmentCurrency: string;
  defaultTaxBehavior: TaxBehaviorOption;
  /**
   * Organization feature settings
   */
  featureSettings: OrganizationFeatureSettings | null;
  subscriptionSettings: OrganizationSubscriptionSettings;
  customerEmailSettings: OrganizationCustomerEmailSettings;
  customerPortalSettings: OrganizationCustomerPortalSettings;
  /**
   * Two-letter country code (ISO 3166-1 alpha-2).
   */
  country?: CountryAlpha2 | null | undefined;
  /**
   * ID of the transactions account.
   */
  accountId: string | null;
  /**
   * ID of the payout account.
   */
  payoutAccountId: string | null;
  capabilities: OrganizationCapabilities;
};

/** @internal */
export const CountryAlpha2$inboundSchema: z.ZodMiniType<
  CountryAlpha2,
  unknown
> = openEnums.inboundSchema(CountryAlpha2);
/** @internal */
export const CountryAlpha2$outboundSchema: z.ZodMiniType<
  string,
  CountryAlpha2
> = openEnums.outboundSchema(CountryAlpha2);

/** @internal */
export const Organization$inboundSchema: z.ZodMiniType<Organization, unknown> =
  z.pipe(
    z.object({
      created_at: z.pipe(
        z.iso.datetime({ offset: true }),
        z.transform(v => new Date(v)),
      ),
      modified_at: z.nullable(
        z.pipe(z.iso.datetime({ offset: true }), z.transform(v => new Date(v))),
      ),
      id: z.string(),
      name: z.string(),
      slug: z.string(),
      avatar_url: z.nullable(z.string()),
      proration_behavior: SubscriptionProrationBehavior$inboundSchema,
      allow_customer_updates: z.boolean(),
      email: z.nullable(z.string()),
      website: z.nullable(z.string()),
      socials: z.array(OrganizationSocialLink$inboundSchema),
      status: OrganizationStatus$inboundSchema,
      details_submitted_at: z.nullable(
        z.pipe(z.iso.datetime({ offset: true }), z.transform(v => new Date(v))),
      ),
      sso_enforced: z.boolean(),
      default_presentment_currency: z.string(),
      default_tax_behavior: TaxBehaviorOption$inboundSchema,
      feature_settings: z.nullable(OrganizationFeatureSettings$inboundSchema),
      subscription_settings: OrganizationSubscriptionSettings$inboundSchema,
      customer_email_settings: OrganizationCustomerEmailSettings$inboundSchema,
      customer_portal_settings:
        OrganizationCustomerPortalSettings$inboundSchema,
      country: z.optional(z.nullable(CountryAlpha2$inboundSchema)),
      account_id: z.nullable(z.string()),
      payout_account_id: z.nullable(z.string()),
      capabilities: OrganizationCapabilities$inboundSchema,
    }),
    z.transform((v) => {
      return remap$(v, {
        "created_at": "createdAt",
        "modified_at": "modifiedAt",
        "avatar_url": "avatarUrl",
        "proration_behavior": "prorationBehavior",
        "allow_customer_updates": "allowCustomerUpdates",
        "details_submitted_at": "detailsSubmittedAt",
        "sso_enforced": "ssoEnforced",
        "default_presentment_currency": "defaultPresentmentCurrency",
        "default_tax_behavior": "defaultTaxBehavior",
        "feature_settings": "featureSettings",
        "subscription_settings": "subscriptionSettings",
        "customer_email_settings": "customerEmailSettings",
        "customer_portal_settings": "customerPortalSettings",
        "account_id": "accountId",
        "payout_account_id": "payoutAccountId",
      });
    }),
  );
/** @internal */
export type Organization$Outbound = {
  created_at: string;
  modified_at: string | null;
  id: string;
  name: string;
  slug: string;
  avatar_url: string | null;
  proration_behavior: string;
  allow_customer_updates: boolean;
  email: string | null;
  website: string | null;
  socials: Array<OrganizationSocialLink$Outbound>;
  status: string;
  details_submitted_at: string | null;
  sso_enforced: boolean;
  default_presentment_currency: string;
  default_tax_behavior: string;
  feature_settings: OrganizationFeatureSettings$Outbound | null;
  subscription_settings: OrganizationSubscriptionSettings$Outbound;
  customer_email_settings: OrganizationCustomerEmailSettings$Outbound;
  customer_portal_settings: OrganizationCustomerPortalSettings$Outbound;
  country?: string | null | undefined;
  account_id: string | null;
  payout_account_id: string | null;
  capabilities: OrganizationCapabilities$Outbound;
};

/** @internal */
export const Organization$outboundSchema: z.ZodMiniType<
  Organization$Outbound,
  Organization
> = z.pipe(
  z.object({
    createdAt: z.pipe(z.date(), z.transform(v => v.toISOString())),
    modifiedAt: z.nullable(z.pipe(z.date(), z.transform(v => v.toISOString()))),
    id: z.string(),
    name: z.string(),
    slug: z.string(),
    avatarUrl: z.nullable(z.string()),
    prorationBehavior: SubscriptionProrationBehavior$outboundSchema,
    allowCustomerUpdates: z.boolean(),
    email: z.nullable(z.string()),
    website: z.nullable(z.string()),
    socials: z.array(OrganizationSocialLink$outboundSchema),
    status: OrganizationStatus$outboundSchema,
    detailsSubmittedAt: z.nullable(
      z.pipe(z.date(), z.transform(v => v.toISOString())),
    ),
    ssoEnforced: z.boolean(),
    defaultPresentmentCurrency: z.string(),
    defaultTaxBehavior: TaxBehaviorOption$outboundSchema,
    featureSettings: z.nullable(OrganizationFeatureSettings$outboundSchema),
    subscriptionSettings: OrganizationSubscriptionSettings$outboundSchema,
    customerEmailSettings: OrganizationCustomerEmailSettings$outboundSchema,
    customerPortalSettings: OrganizationCustomerPortalSettings$outboundSchema,
    country: z.optional(z.nullable(CountryAlpha2$outboundSchema)),
    accountId: z.nullable(z.string()),
    payoutAccountId: z.nullable(z.string()),
    capabilities: OrganizationCapabilities$outboundSchema,
  }),
  z.transform((v) => {
    return remap$(v, {
      createdAt: "created_at",
      modifiedAt: "modified_at",
      avatarUrl: "avatar_url",
      prorationBehavior: "proration_behavior",
      allowCustomerUpdates: "allow_customer_updates",
      detailsSubmittedAt: "details_submitted_at",
      ssoEnforced: "sso_enforced",
      defaultPresentmentCurrency: "default_presentment_currency",
      defaultTaxBehavior: "default_tax_behavior",
      featureSettings: "feature_settings",
      subscriptionSettings: "subscription_settings",
      customerEmailSettings: "customer_email_settings",
      customerPortalSettings: "customer_portal_settings",
      accountId: "account_id",
      payoutAccountId: "payout_account_id",
    });
  }),
);

export function organizationToJSON(organization: Organization): string {
  return JSON.stringify(Organization$outboundSchema.parse(organization));
}
export function organizationFromJSON(
  jsonString: string,
): SafeParseResult<Organization, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => Organization$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'Organization' from JSON`,
  );
}
