/*
 * 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 { ClosedEnum } from "../../types/enums.js";
import { Result as SafeParseResult } from "../../types/fp.js";
import * as components from "../components/index.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";

/**
 * The tag IDs to filter the links by.
 */
export type QueryParamTagIds = string | Array<string>;

/**
 * The unique name of the tags assigned to the short link (case insensitive).
 */
export type QueryParamTagNames = string | Array<string>;

/**
 * The field to sort the links by. The default is `createdAt`.
 */
export const SortBy = {
  CreatedAt: "createdAt",
  Clicks: "clicks",
  SaleAmount: "saleAmount",
  LastClicked: "lastClicked",
} as const;
/**
 * The field to sort the links by. The default is `createdAt`.
 */
export type SortBy = ClosedEnum<typeof SortBy>;

/**
 * The sort order. The default is `desc`.
 */
export const SortOrder = {
  Asc: "asc",
  Desc: "desc",
} as const;
/**
 * The sort order. The default is `desc`.
 */
export type SortOrder = ClosedEnum<typeof SortOrder>;

/**
 * DEPRECATED. Use `sortBy` instead.
 *
 * @deprecated enum: This will be removed in a future release, please migrate away from it as soon as possible.
 */
export const Sort = {
  CreatedAt: "createdAt",
  Clicks: "clicks",
  SaleAmount: "saleAmount",
  LastClicked: "lastClicked",
} as const;
/**
 * DEPRECATED. Use `sortBy` instead.
 *
 * @deprecated enum: This will be removed in a future release, please migrate away from it as soon as possible.
 */
export type Sort = ClosedEnum<typeof Sort>;

export type GetLinksRequest = {
  /**
   * The domain to filter the links by. E.g. `ac.me`. If not provided, all links for the workspace will be returned.
   */
  domain?: string | undefined;
  /**
   * Deprecated. Use `tagIds` instead. The tag ID to filter the links by.
   */
  tagId?: string | undefined;
  /**
   * The tag IDs to filter the links by.
   */
  tagIds?: string | Array<string> | undefined;
  /**
   * The unique name of the tags assigned to the short link (case insensitive).
   */
  tagNames?: string | Array<string> | undefined;
  /**
   * The search term to filter the links by. The search term will be matched against the short link slug and the destination url.
   */
  search?: string | undefined;
  /**
   * The user ID to filter the links by.
   */
  userId?: string | undefined;
  /**
   * The ID of the tenant that created the link inside your system. If set, will only return links for the specified tenant.
   */
  tenantId?: string | undefined;
  /**
   * Whether to include archived links in the response. Defaults to `false` if not provided.
   */
  showArchived?: boolean | undefined;
  /**
   * DEPRECATED. Filter for links that have at least one tag assigned to them.
   */
  withTags?: boolean | undefined;
  /**
   * The field to sort the links by. The default is `createdAt`.
   */
  sortBy?: SortBy | undefined;
  /**
   * The sort order. The default is `desc`.
   */
  sortOrder?: SortOrder | undefined;
  /**
   * DEPRECATED. Use `sortBy` instead.
   */
  sort?: Sort | undefined;
  /**
   * The page number for pagination.
   */
  page?: number | undefined;
  /**
   * The number of items per page.
   */
  pageSize?: number | undefined;
};

export type GetLinksResponse = {
  result: Array<components.LinkSchema>;
};

/** @internal */
export const QueryParamTagIds$inboundSchema: z.ZodType<
  QueryParamTagIds,
  z.ZodTypeDef,
  unknown
> = z.union([z.string(), z.array(z.string())]);

/** @internal */
export type QueryParamTagIds$Outbound = string | Array<string>;

/** @internal */
export const QueryParamTagIds$outboundSchema: z.ZodType<
  QueryParamTagIds$Outbound,
  z.ZodTypeDef,
  QueryParamTagIds
> = z.union([z.string(), z.array(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 QueryParamTagIds$ {
  /** @deprecated use `QueryParamTagIds$inboundSchema` instead. */
  export const inboundSchema = QueryParamTagIds$inboundSchema;
  /** @deprecated use `QueryParamTagIds$outboundSchema` instead. */
  export const outboundSchema = QueryParamTagIds$outboundSchema;
  /** @deprecated use `QueryParamTagIds$Outbound` instead. */
  export type Outbound = QueryParamTagIds$Outbound;
}

export function queryParamTagIdsToJSON(
  queryParamTagIds: QueryParamTagIds,
): string {
  return JSON.stringify(
    QueryParamTagIds$outboundSchema.parse(queryParamTagIds),
  );
}

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

/** @internal */
export const QueryParamTagNames$inboundSchema: z.ZodType<
  QueryParamTagNames,
  z.ZodTypeDef,
  unknown
> = z.union([z.string(), z.array(z.string())]);

/** @internal */
export type QueryParamTagNames$Outbound = string | Array<string>;

/** @internal */
export const QueryParamTagNames$outboundSchema: z.ZodType<
  QueryParamTagNames$Outbound,
  z.ZodTypeDef,
  QueryParamTagNames
> = z.union([z.string(), z.array(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 QueryParamTagNames$ {
  /** @deprecated use `QueryParamTagNames$inboundSchema` instead. */
  export const inboundSchema = QueryParamTagNames$inboundSchema;
  /** @deprecated use `QueryParamTagNames$outboundSchema` instead. */
  export const outboundSchema = QueryParamTagNames$outboundSchema;
  /** @deprecated use `QueryParamTagNames$Outbound` instead. */
  export type Outbound = QueryParamTagNames$Outbound;
}

export function queryParamTagNamesToJSON(
  queryParamTagNames: QueryParamTagNames,
): string {
  return JSON.stringify(
    QueryParamTagNames$outboundSchema.parse(queryParamTagNames),
  );
}

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

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

/** @internal */
export const SortBy$outboundSchema: z.ZodNativeEnum<typeof SortBy> =
  SortBy$inboundSchema;

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

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

/** @internal */
export const SortOrder$outboundSchema: z.ZodNativeEnum<typeof SortOrder> =
  SortOrder$inboundSchema;

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

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

/** @internal */
export const Sort$outboundSchema: z.ZodNativeEnum<typeof Sort> =
  Sort$inboundSchema;

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

/** @internal */
export const GetLinksRequest$inboundSchema: z.ZodType<
  GetLinksRequest,
  z.ZodTypeDef,
  unknown
> = z.object({
  domain: z.string().optional(),
  tagId: z.string().optional(),
  tagIds: z.union([z.string(), z.array(z.string())]).optional(),
  tagNames: z.union([z.string(), z.array(z.string())]).optional(),
  search: z.string().optional(),
  userId: z.string().optional(),
  tenantId: z.string().optional(),
  showArchived: z.boolean().default(false),
  withTags: z.boolean().default(false),
  sortBy: SortBy$inboundSchema.default("createdAt"),
  sortOrder: SortOrder$inboundSchema.default("desc"),
  sort: Sort$inboundSchema.default("createdAt"),
  page: z.number().default(1),
  pageSize: z.number().default(100),
});

/** @internal */
export type GetLinksRequest$Outbound = {
  domain?: string | undefined;
  tagId?: string | undefined;
  tagIds?: string | Array<string> | undefined;
  tagNames?: string | Array<string> | undefined;
  search?: string | undefined;
  userId?: string | undefined;
  tenantId?: string | undefined;
  showArchived: boolean;
  withTags: boolean;
  sortBy: string;
  sortOrder: string;
  sort: string;
  page: number;
  pageSize: number;
};

/** @internal */
export const GetLinksRequest$outboundSchema: z.ZodType<
  GetLinksRequest$Outbound,
  z.ZodTypeDef,
  GetLinksRequest
> = z.object({
  domain: z.string().optional(),
  tagId: z.string().optional(),
  tagIds: z.union([z.string(), z.array(z.string())]).optional(),
  tagNames: z.union([z.string(), z.array(z.string())]).optional(),
  search: z.string().optional(),
  userId: z.string().optional(),
  tenantId: z.string().optional(),
  showArchived: z.boolean().default(false),
  withTags: z.boolean().default(false),
  sortBy: SortBy$outboundSchema.default("createdAt"),
  sortOrder: SortOrder$outboundSchema.default("desc"),
  sort: Sort$outboundSchema.default("createdAt"),
  page: z.number().default(1),
  pageSize: z.number().default(100),
});

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

export function getLinksRequestToJSON(
  getLinksRequest: GetLinksRequest,
): string {
  return JSON.stringify(GetLinksRequest$outboundSchema.parse(getLinksRequest));
}

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

/** @internal */
export const GetLinksResponse$inboundSchema: z.ZodType<
  GetLinksResponse,
  z.ZodTypeDef,
  unknown
> = z.object({
  Result: z.array(components.LinkSchema$inboundSchema),
}).transform((v) => {
  return remap$(v, {
    "Result": "result",
  });
});

/** @internal */
export type GetLinksResponse$Outbound = {
  Result: Array<components.LinkSchema$Outbound>;
};

/** @internal */
export const GetLinksResponse$outboundSchema: z.ZodType<
  GetLinksResponse$Outbound,
  z.ZodTypeDef,
  GetLinksResponse
> = z.object({
  result: z.array(components.LinkSchema$outboundSchema),
}).transform((v) => {
  return remap$(v, {
    result: "Result",
  });
});

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

export function getLinksResponseToJSON(
  getLinksResponse: GetLinksResponse,
): string {
  return JSON.stringify(
    GetLinksResponse$outboundSchema.parse(getLinksResponse),
  );
}

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