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

import * as z from "zod";
import { remap as remap$ } from "../../lib/primitives.js";
import { safeParse } from "../../lib/schemas.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";

export type Link = {
  rel: string;
  href: string;
};

export type Organization = {
  organizationId: string;
  links: Array<Link>;
};

export type Account = {
  accountId: string;
  isDefault: boolean;
  accountName: string;
  baseUri: string;
  organization?: Organization | undefined;
};

export type UserInfo = {
  sub: string;
  name: string;
  givenName: string;
  familyName: string;
  created: string;
  email: string;
  accounts: Array<Account>;
};

/** @internal */
export const Link$inboundSchema: z.ZodType<Link, z.ZodTypeDef, unknown> = z
  .object({
    rel: z.string(),
    href: z.string(),
  });

/** @internal */
export type Link$Outbound = {
  rel: string;
  href: string;
};

/** @internal */
export const Link$outboundSchema: z.ZodType<Link$Outbound, z.ZodTypeDef, Link> =
  z.object({
    rel: z.string(),
    href: z.string(),
  });

/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
export namespace Link$ {
  /** @deprecated use `Link$inboundSchema` instead. */
  export const inboundSchema = Link$inboundSchema;
  /** @deprecated use `Link$outboundSchema` instead. */
  export const outboundSchema = Link$outboundSchema;
  /** @deprecated use `Link$Outbound` instead. */
  export type Outbound = Link$Outbound;
}

export function linkToJSON(link: Link): string {
  return JSON.stringify(Link$outboundSchema.parse(link));
}

export function linkFromJSON(
  jsonString: string,
): SafeParseResult<Link, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => Link$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'Link' from JSON`,
  );
}

/** @internal */
export const Organization$inboundSchema: z.ZodType<
  Organization,
  z.ZodTypeDef,
  unknown
> = z.object({
  organization_id: z.string(),
  links: z.array(z.lazy(() => Link$inboundSchema)),
}).transform((v) => {
  return remap$(v, {
    "organization_id": "organizationId",
  });
});

/** @internal */
export type Organization$Outbound = {
  organization_id: string;
  links: Array<Link$Outbound>;
};

/** @internal */
export const Organization$outboundSchema: z.ZodType<
  Organization$Outbound,
  z.ZodTypeDef,
  Organization
> = z.object({
  organizationId: z.string(),
  links: z.array(z.lazy(() => Link$outboundSchema)),
}).transform((v) => {
  return remap$(v, {
    organizationId: "organization_id",
  });
});

/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
export namespace Organization$ {
  /** @deprecated use `Organization$inboundSchema` instead. */
  export const inboundSchema = Organization$inboundSchema;
  /** @deprecated use `Organization$outboundSchema` instead. */
  export const outboundSchema = Organization$outboundSchema;
  /** @deprecated use `Organization$Outbound` instead. */
  export type Outbound = Organization$Outbound;
}

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`,
  );
}

/** @internal */
export const Account$inboundSchema: z.ZodType<Account, z.ZodTypeDef, unknown> =
  z.object({
    account_id: z.string(),
    is_default: z.boolean(),
    account_name: z.string(),
    base_uri: z.string(),
    organization: z.lazy(() => Organization$inboundSchema).optional(),
  }).transform((v) => {
    return remap$(v, {
      "account_id": "accountId",
      "is_default": "isDefault",
      "account_name": "accountName",
      "base_uri": "baseUri",
    });
  });

/** @internal */
export type Account$Outbound = {
  account_id: string;
  is_default: boolean;
  account_name: string;
  base_uri: string;
  organization?: Organization$Outbound | undefined;
};

/** @internal */
export const Account$outboundSchema: z.ZodType<
  Account$Outbound,
  z.ZodTypeDef,
  Account
> = z.object({
  accountId: z.string(),
  isDefault: z.boolean(),
  accountName: z.string(),
  baseUri: z.string(),
  organization: z.lazy(() => Organization$outboundSchema).optional(),
}).transform((v) => {
  return remap$(v, {
    accountId: "account_id",
    isDefault: "is_default",
    accountName: "account_name",
    baseUri: "base_uri",
  });
});

/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
export namespace Account$ {
  /** @deprecated use `Account$inboundSchema` instead. */
  export const inboundSchema = Account$inboundSchema;
  /** @deprecated use `Account$outboundSchema` instead. */
  export const outboundSchema = Account$outboundSchema;
  /** @deprecated use `Account$Outbound` instead. */
  export type Outbound = Account$Outbound;
}

export function accountToJSON(account: Account): string {
  return JSON.stringify(Account$outboundSchema.parse(account));
}

export function accountFromJSON(
  jsonString: string,
): SafeParseResult<Account, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => Account$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'Account' from JSON`,
  );
}

/** @internal */
export const UserInfo$inboundSchema: z.ZodType<
  UserInfo,
  z.ZodTypeDef,
  unknown
> = z.object({
  sub: z.string(),
  name: z.string(),
  given_name: z.string(),
  family_name: z.string(),
  created: z.string(),
  email: z.string(),
  accounts: z.array(z.lazy(() => Account$inboundSchema)),
}).transform((v) => {
  return remap$(v, {
    "given_name": "givenName",
    "family_name": "familyName",
  });
});

/** @internal */
export type UserInfo$Outbound = {
  sub: string;
  name: string;
  given_name: string;
  family_name: string;
  created: string;
  email: string;
  accounts: Array<Account$Outbound>;
};

/** @internal */
export const UserInfo$outboundSchema: z.ZodType<
  UserInfo$Outbound,
  z.ZodTypeDef,
  UserInfo
> = z.object({
  sub: z.string(),
  name: z.string(),
  givenName: z.string(),
  familyName: z.string(),
  created: z.string(),
  email: z.string(),
  accounts: z.array(z.lazy(() => Account$outboundSchema)),
}).transform((v) => {
  return remap$(v, {
    givenName: "given_name",
    familyName: "family_name",
  });
});

/**
 * @internal
 * @deprecated This namespace will be removed in future versions. Use schemas and types that are exported directly from this module.
 */
export namespace UserInfo$ {
  /** @deprecated use `UserInfo$inboundSchema` instead. */
  export const inboundSchema = UserInfo$inboundSchema;
  /** @deprecated use `UserInfo$outboundSchema` instead. */
  export const outboundSchema = UserInfo$outboundSchema;
  /** @deprecated use `UserInfo$Outbound` instead. */
  export type Outbound = UserInfo$Outbound;
}

export function userInfoToJSON(userInfo: UserInfo): string {
  return JSON.stringify(UserInfo$outboundSchema.parse(userInfo));
}

export function userInfoFromJSON(
  jsonString: string,
): SafeParseResult<UserInfo, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => UserInfo$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'UserInfo' from JSON`,
  );
}
