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

import * as z from "zod/v3";
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 { UserProfile, UserProfile$inboundSchema } from "./userprofile.js";

/**
 * Your current mailing list status
 */
export enum MailingListStatus {
  Active = "active",
  Unsubscribed = "unsubscribed",
  Removed = "removed",
}

export enum ServiceStatus {
  Online = "online",
  Offline = "offline",
}
export type ServiceStatusOpen = OpenEnum<typeof ServiceStatus>;

export type Service = {
  identifier: string;
  endpoint: string;
  token: string | null;
  secret: string | null;
  status: ServiceStatusOpen;
};

/**
 * String representation of subscriptionActive
 */
export enum SubscriptionStatus1 {
  Inactive = "Inactive",
  Active = "Active",
}
/**
 * String representation of subscriptionActive
 */
export type SubscriptionStatus1Open = OpenEnum<typeof SubscriptionStatus1>;

/**
 * If the account's Plex Pass subscription is active
 */
export type Subscription1 = {
  /**
   * List of features allowed on your Plex Pass subscription
   */
  features?: Array<string> | undefined;
  /**
   * If the account's Plex Pass subscription is active
   */
  active?: boolean | undefined;
  /**
   * Date the account subscribed to Plex Pass
   */
  subscribedAt?: string | null | undefined;
  /**
   * String representation of subscriptionActive
   */
  status?: SubscriptionStatus1Open | undefined;
  /**
   * Payment service used for your Plex Pass subscription
   */
  paymentService?: string | null | undefined;
  /**
   * Name of Plex Pass subscription plan
   */
  plan?: string | null | undefined;
};

/**
 * String representation of subscriptionActive
 */
export enum SubscriptionStatus2 {
  Inactive = "Inactive",
  Active = "Active",
}
/**
 * String representation of subscriptionActive
 */
export type SubscriptionStatus2Open = OpenEnum<typeof SubscriptionStatus2>;

export type Subscription2 = {
  /**
   * List of features allowed on your Plex Pass subscription
   */
  features?: Array<string> | undefined;
  /**
   * If the account's Plex Pass subscription is active
   */
  active?: boolean | undefined;
  /**
   * Date the account subscribed to Plex Pass
   */
  subscribedAt?: string | null | undefined;
  /**
   * String representation of subscriptionActive
   */
  status?: SubscriptionStatus2Open | undefined;
  /**
   * Payment service used for your Plex Pass subscription
   */
  paymentService?: string | null | undefined;
  /**
   * Name of Plex Pass subscription plan
   */
  plan?: string | null | undefined;
};

export type UserPlexAccount = {
  /**
   * Unknown
   */
  adsConsent?: boolean | null | undefined;
  adsConsentReminderAt?: number | null | undefined;
  adsConsentSetAt?: number | null | undefined;
  /**
   * Unknown
   */
  anonymous?: boolean | null | undefined;
  /**
   * The account token
   */
  authToken: string;
  /**
   * If the two-factor authentication backup codes have been created
   */
  backupCodesCreated?: boolean | undefined;
  /**
   * If the account has been confirmed
   */
  confirmed?: boolean | undefined;
  /**
   * The account country
   */
  country?: string | undefined;
  /**
   * The account email address
   */
  email: string;
  /**
   * If login with email only is enabled
   */
  emailOnlyAuth?: boolean | undefined;
  /**
   * If experimental features are enabled
   */
  experimentalFeatures?: boolean | undefined;
  /**
   * Your account full name
   */
  friendlyName: string;
  /**
   * List of devices your allowed to use with this account
   */
  entitlements?: Array<string> | undefined;
  /**
   * If the account is a Plex Home guest user
   */
  guest?: boolean | undefined;
  /**
   * If the account has a password
   */
  hasPassword?: boolean | undefined;
  /**
   * If the account is a Plex Home user
   */
  home?: boolean | undefined;
  /**
   * If the account is the Plex Home admin
   */
  homeAdmin?: boolean | undefined;
  /**
   * The number of accounts in the Plex Home
   */
  homeSize?: number | undefined;
  /**
   * The Plex account ID
   */
  id: number;
  /**
   * Unix epoch datetime in seconds
   */
  joinedAt: number;
  /**
   * The account locale
   */
  locale?: string | null | undefined;
  /**
   * If you are subscribed to the Plex newsletter
   */
  mailingListActive?: boolean | undefined;
  /**
   * Your current mailing list status
   */
  mailingListStatus?: MailingListStatus | undefined;
  /**
   * The maximum number of accounts allowed in the Plex Home
   */
  maxHomeSize?: number | undefined;
  /**
   * [Might be removed] The hashed Plex Home PIN
   *
   * @deprecated field: This will be removed in a future release, please migrate away from it as soon as possible.
   */
  pin?: string | undefined;
  profile?: UserProfile | undefined;
  /**
   * If the account has a Plex Home PIN enabled
   */
  protected?: boolean | undefined;
  /**
   * Unix epoch datetime in seconds
   */
  rememberExpiresAt?: number | undefined;
  /**
   * If the account is a Plex Home managed user
   */
  restricted?: boolean | undefined;
  /**
   * [Might be removed] List of account roles. Plexpass membership listed here
   */
  roles?: Array<string> | undefined;
  /**
   * Unknown
   */
  scrobbleTypes?: string | undefined;
  services?: Array<Service> | undefined;
  /**
   * If the account's Plex Pass subscription is active
   */
  subscription?: Subscription1 | undefined;
  /**
   * Description of the Plex Pass subscription
   */
  subscriptionDescription?: string | null | undefined;
  subscriptions?: Array<Subscription2> | undefined;
  /**
   * URL of the account thumbnail
   */
  thumb?: string | undefined;
  /**
   * The title of the account (username or friendly name)
   */
  title: string;
  /**
   * If two-factor authentication is enabled
   */
  twoFactorEnabled?: boolean | undefined;
  /**
   * The account username
   */
  username: string;
  /**
   * The account UUID
   */
  uuid: string;
  attributionPartner?: string | null | undefined;
};

/** @internal */
export const MailingListStatus$inboundSchema: z.ZodNativeEnum<
  typeof MailingListStatus
> = z.nativeEnum(MailingListStatus);

/** @internal */
export const ServiceStatus$inboundSchema: z.ZodType<
  ServiceStatusOpen,
  z.ZodTypeDef,
  unknown
> = openEnums.inboundSchema(ServiceStatus);

/** @internal */
export const Service$inboundSchema: z.ZodType<Service, z.ZodTypeDef, unknown> =
  z.object({
    identifier: z.string(),
    endpoint: z.string(),
    token: z.nullable(z.string()),
    secret: z.nullable(z.string()),
    status: ServiceStatus$inboundSchema,
  });

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

/** @internal */
export const SubscriptionStatus1$inboundSchema: z.ZodType<
  SubscriptionStatus1Open,
  z.ZodTypeDef,
  unknown
> = openEnums.inboundSchema(SubscriptionStatus1);

/** @internal */
export const Subscription1$inboundSchema: z.ZodType<
  Subscription1,
  z.ZodTypeDef,
  unknown
> = z.object({
  features: z.array(z.string()).optional(),
  active: z.boolean().optional(),
  subscribedAt: z.nullable(z.string()).optional(),
  status: SubscriptionStatus1$inboundSchema.optional(),
  paymentService: z.nullable(z.string()).optional(),
  plan: z.nullable(z.string()).optional(),
});

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

/** @internal */
export const SubscriptionStatus2$inboundSchema: z.ZodType<
  SubscriptionStatus2Open,
  z.ZodTypeDef,
  unknown
> = openEnums.inboundSchema(SubscriptionStatus2);

/** @internal */
export const Subscription2$inboundSchema: z.ZodType<
  Subscription2,
  z.ZodTypeDef,
  unknown
> = z.object({
  features: z.array(z.string()).optional(),
  active: z.boolean().optional(),
  subscribedAt: z.nullable(z.string()).optional(),
  status: SubscriptionStatus2$inboundSchema.optional(),
  paymentService: z.nullable(z.string()).optional(),
  plan: z.nullable(z.string()).optional(),
});

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

/** @internal */
export const UserPlexAccount$inboundSchema: z.ZodType<
  UserPlexAccount,
  z.ZodTypeDef,
  unknown
> = z.object({
  adsConsent: z.nullable(z.boolean()).optional(),
  adsConsentReminderAt: z.nullable(z.number().int()).optional(),
  adsConsentSetAt: z.nullable(z.number().int()).optional(),
  anonymous: z.nullable(z.boolean().default(false)),
  authToken: z.string(),
  backupCodesCreated: z.boolean().default(false),
  confirmed: z.boolean().default(false),
  country: z.string().optional(),
  email: z.string(),
  emailOnlyAuth: z.boolean().default(false),
  experimentalFeatures: z.boolean().default(false),
  friendlyName: z.string(),
  entitlements: z.array(z.string()).optional(),
  guest: z.boolean().default(false),
  hasPassword: z.boolean().default(true),
  home: z.boolean().default(false),
  homeAdmin: z.boolean().default(false),
  homeSize: z.number().int().optional(),
  id: z.number().int(),
  joinedAt: z.number().int(),
  locale: z.nullable(z.string()).optional(),
  mailingListActive: z.boolean().default(false),
  mailingListStatus: MailingListStatus$inboundSchema.optional(),
  maxHomeSize: z.number().int().optional(),
  pin: z.string().optional(),
  profile: UserProfile$inboundSchema.optional(),
  protected: z.boolean().default(false),
  rememberExpiresAt: z.number().int().optional(),
  restricted: z.boolean().default(false),
  roles: z.array(z.string()).optional(),
  scrobbleTypes: z.string().optional(),
  services: z.array(z.lazy(() => Service$inboundSchema)).optional(),
  subscription: z.lazy(() => Subscription1$inboundSchema).optional(),
  subscriptionDescription: z.nullable(z.string()).optional(),
  subscriptions: z.array(z.lazy(() => Subscription2$inboundSchema)).optional(),
  thumb: z.string().optional(),
  title: z.string(),
  twoFactorEnabled: z.boolean().default(false),
  username: z.string(),
  uuid: z.string(),
  attributionPartner: z.nullable(z.string()).optional(),
});

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