import { z } from "zod";

import {
  actionSuccessSchema,
  addressScreeningResponseSchema,
  allowlistEntriesResponseSchema,
  allowlistEntrySchema,
  apiKeyControlProfileActivationResponseSchema,
  apiKeyControlProfileResponseSchema,
  apiKeyControlProfileRevisionResponseSchema,
  apiKeyDetailSchema,
  apiKeyPolicyBindingsResponseSchema,
  apiKeyResponseSchema,
  assetProfileFieldOptionsResponseSchema,
  assetProfileResponseSchema,
  counterpartyAccountResponseSchema,
  counterpartyFieldOptionsResponseSchema,
  counterpartyRequirementsResponseSchema,
  counterpartyResponseSchema,
  currentUserResponseSchema,
  custodyConfigResponseSchema,
  custodyConfigsResponseSchema,
  custodyWalletAggregateResponseSchema,
  custodyWalletByIdResponseSchema,
  custodyWalletResponseSchema,
  custodyWalletsResponseSchema,
  deleteWalletResponseSchema,
  executeBurnResponseSchema,
  executeForceBurnResponseSchema,
  executeMintResponseSchema,
  executePauseResponseSchema,
  executeSeizeResponseSchema,
  executeUnpauseResponseSchema,
  executeUpdateAuthorityResponseSchema,
  frozenAccountResponseSchema,
  frozenAccountSchema,
  inviteMemberResponseSchema,
  listApiKeysResponseSchema,
  listAssetProfilesResponseSchema,
  listCounterpartiesResponseSchema,
  listCounterpartyAccountsResponseSchema,
  listMembersResponseSchema,
  listProjectApiKeysResponseSchema,
  listProjectMembersResponseSchema,
  listProjectsResponseSchema,
  listSessionsResponseSchema,
  listTemplatesResponseSchema,
  offrampCurrenciesResponseSchema,
  onboardingCompleteResponseSchema,
  onboardingStatusResponseSchema,
  onrampCurrenciesResponseSchema,
  onrampQuoteResponseSchema,
  organizationSchema,
  paginatedResponseSchema,
  paymentRecurringPaymentCollectionResponseSchema,
  paymentRecurringPaymentListResponseSchema,
  paymentRecurringPaymentResponseSchema,
  paymentSubscriptionCollectionAttemptListResponseSchema,
  paymentSubscriptionCollectionAttemptResponseSchema,
  paymentSubscriptionListResponseSchema,
  paymentSubscriptionPlanListResponseSchema,
  paymentSubscriptionPlanResponseSchema,
  paymentSubscriptionResponseSchema,
  policyControlInventoryResponseSchema,
  prepareBurnResponseSchema,
  prepareDeployMetadataResponseSchema,
  prepareDeployResponseSchema,
  prepareForceBurnResponseSchema,
  prepareMintResponseSchema,
  preparePaymentSubscriptionAuthorizationResponseSchema,
  preparePaymentSubscriptionCollectionResponseSchema,
  preparePaymentSubscriptionLifecycleResponseSchema,
  preparePaymentSubscriptionPlanResponseSchema,
  prepareSeizeResponseSchema,
  prepareUpdateAuthorityResponseSchema,
  projectMemberResponseSchema,
  projectResponseSchema,
  revokeApiKeyResponseSchema,
  rotateApiKeyResponseSchema,
  rpcProvidersResponseSchema,
  rpcRelayResponseSchema,
  sandboxTransferSimulationResponseSchema,
  signerCheckResponseSchema,
  successResponseSchema,
  switchProviderOptionsResponseSchema,
  tokenAllowlistEntrySchema,
  tokenAllowlistResponseSchema,
  tokenResponseSchema,
  tokenSchema,
  tokenTemplateResponseSchema,
  tokenTransactionListItemSchema,
  tokenTransactionSchema,
  tokenWithAssetProfileResponseSchema,
  transferBatchEstimateResponseSchema,
  transferBatchResponseSchema,
  transferBatchSchema,
  transferResponseSchema,
  transferSchema,
  walletApprovalRequestResponseSchema,
  walletApprovalRequestsResponseSchema,
  walletBalancesResponseSchema,
  walletControlProfileRevisionHistorySchema,
  walletPolicyEvaluationDetailSchema,
  walletPolicyEvaluationResponseSchema,
  walletPolicyResponseSchema,
} from "../schemas";

export const organizationResponse = successResponseSchema(organizationSchema);

export const listMembersResponse = successResponseSchema(listMembersResponseSchema);
export const inviteMemberResponse = successResponseSchema(inviteMemberResponseSchema);
export const actionSuccessResponse = successResponseSchema(actionSuccessSchema);

export const listApiKeysResponse = successResponseSchema(listApiKeysResponseSchema);
export const apiKeyDetailResponse = successResponseSchema(apiKeyDetailSchema);
export const apiKeyCreateResponse = successResponseSchema(apiKeyResponseSchema);
export const apiKeyRotateResponse = successResponseSchema(rotateApiKeyResponseSchema);
export const apiKeyRevokeResponse = successResponseSchema(revokeApiKeyResponseSchema);
export const apiKeyControlProfileResponse = successResponseSchema(
  apiKeyControlProfileResponseSchema
);
export const apiKeyControlProfileRevisionResponse = successResponseSchema(
  apiKeyControlProfileRevisionResponseSchema
);
export const apiKeyControlProfileActivationResponse = successResponseSchema(
  apiKeyControlProfileActivationResponseSchema
);
export const apiKeyPolicyBindingsResponse = successResponseSchema(
  apiKeyPolicyBindingsResponseSchema
);

export const assetProfileResponse = successResponseSchema(assetProfileResponseSchema);
export const assetProfileFieldOptionsResponse = successResponseSchema(
  assetProfileFieldOptionsResponseSchema
);
export const listAssetProfilesResponse = successResponseSchema(listAssetProfilesResponseSchema);

export const counterpartyResponse = successResponseSchema(counterpartyResponseSchema);
export const counterpartyFieldOptionsResponse = successResponseSchema(
  counterpartyFieldOptionsResponseSchema
);
export const counterpartyRequirementsResponse = successResponseSchema(
  counterpartyRequirementsResponseSchema
);
export const listCounterpartiesResponse = successResponseSchema(listCounterpartiesResponseSchema);
export const counterpartyAccountResponse = successResponseSchema(counterpartyAccountResponseSchema);
export const listCounterpartyAccountsResponse = successResponseSchema(
  listCounterpartyAccountsResponseSchema
);

export const projectResponse = successResponseSchema(projectResponseSchema);
export const listProjectsResponse = successResponseSchema(listProjectsResponseSchema);
export const listProjectMembersResponse = successResponseSchema(listProjectMembersResponseSchema);
export const projectMemberResponse = successResponseSchema(projectMemberResponseSchema);
export const listProjectApiKeysResponse = successResponseSchema(listProjectApiKeysResponseSchema);
export const rpcProvidersResponse = successResponseSchema(rpcProvidersResponseSchema);
export const rpcRelayResponse = successResponseSchema(rpcRelayResponseSchema);

export const tokenResponse = successResponseSchema(tokenResponseSchema);
export const tokenWithAssetProfileResponse = successResponseSchema(
  tokenWithAssetProfileResponseSchema
);
export const tokenListResponse = paginatedResponseSchema(tokenSchema);
export const tokenTransactionsResponse = paginatedResponseSchema(tokenTransactionSchema);
export const issuanceTransactionsResponse = paginatedResponseSchema(tokenTransactionListItemSchema);
export const tokenAllowlistListResponse = paginatedResponseSchema(tokenAllowlistEntrySchema);
export const tokenAllowlistResponse = successResponseSchema(tokenAllowlistResponseSchema);
export const tokenAllowlistLabelsResponse = successResponseSchema(
  z.object({
    labels: z.array(z.string()).openapi({
      description: "Distinct labels used across the token's active control-list entries.",
      example: ["Treasury", "Market maker"],
    }),
    total: z.number().int().openapi({
      description: "Total active control-list entries (unfiltered), for the summary count.",
      example: 42,
    }),
  })
);
export const tokenListFacetsResponse = successResponseSchema(
  z.object({
    templates: z
      .array(
        z.object({
          template: z.string().openapi({ example: "stablecoin" }),
          count: z.number().int().openapi({ example: 12 }),
        })
      )
      .openapi({
        description:
          "Template ids present in the project with their token counts. Includes legacy ids still stored on older tokens.",
      }),
    deploymentStatuses: z
      .object({
        draft: z.number().int().openapi({ example: 3 }),
        active: z.number().int().openapi({ example: 8 }),
        paused: z.number().int().openapi({ example: 1 }),
      })
      .openapi({
        description:
          "Token counts per derived lifecycle state (draft until deployed, paused when the mint is paused, active otherwise).",
      }),
    total: z.number().int().openapi({
      description:
        "Total tokens in the project, unfiltered — distinguishes an empty project from an over-filtered list.",
      example: 12,
    }),
  })
);
export const frozenAccountResponse = successResponseSchema(frozenAccountResponseSchema);
export const frozenAccountListResponse = paginatedResponseSchema(frozenAccountSchema);

const assetAuditEventSchema = z
  .object({
    id: z.string(),
    action: z.string().openapi({ example: "freeze" }),
    resourceType: z.string().openapi({ example: "frozen_account" }),
    resourceId: z.string().nullable(),
    actorType: z.enum(["user", "api_key", "system"]).openapi({ example: "user" }),
    actorLabel: z.string().openapi({ example: "Jordan Lee" }),
    status: z.enum(["success", "failure"]).openapi({ example: "success" }),
    createdAt: z.string().openapi({ example: "2026-07-19T12:00:00.000Z" }),
    metadata: z.record(z.string(), z.unknown()).nullable(),
  })
  .openapi({ description: "A single audit event scoped to an asset." });

export const assetAuditListResponse = paginatedResponseSchema(assetAuditEventSchema);

export const prepareDeployResponse = successResponseSchema(prepareDeployResponseSchema);
export const prepareDeployMetadataResponse = successResponseSchema(
  prepareDeployMetadataResponseSchema
);
export const prepareMintResponse = successResponseSchema(prepareMintResponseSchema);
export const executeMintResponse = successResponseSchema(executeMintResponseSchema);
export const prepareBurnResponse = successResponseSchema(prepareBurnResponseSchema);
export const executeBurnResponse = successResponseSchema(executeBurnResponseSchema);
export const prepareSeizeResponse = successResponseSchema(prepareSeizeResponseSchema);
export const executeSeizeResponse = successResponseSchema(executeSeizeResponseSchema);
export const prepareForceBurnResponse = successResponseSchema(prepareForceBurnResponseSchema);
export const executeForceBurnResponse = successResponseSchema(executeForceBurnResponseSchema);
export const prepareUpdateAuthorityResponse = successResponseSchema(
  prepareUpdateAuthorityResponseSchema
);
export const executeUpdateAuthorityResponse = successResponseSchema(
  executeUpdateAuthorityResponseSchema
);
export const executePauseResponse = successResponseSchema(executePauseResponseSchema);
export const executeUnpauseResponse = successResponseSchema(executeUnpauseResponseSchema);

export const currentUserResponse = successResponseSchema(currentUserResponseSchema);
export const listSessionsResponse = successResponseSchema(listSessionsResponseSchema);
export const custodyConfigResponse = successResponseSchema(custodyConfigResponseSchema);
export const custodyConfigsResponse = successResponseSchema(custodyConfigsResponseSchema);
export const custodyWalletResponse = successResponseSchema(custodyWalletResponseSchema);
export const custodyWalletsResponse = successResponseSchema(custodyWalletsResponseSchema);
export const custodyWalletAggregateResponse = successResponseSchema(
  custodyWalletAggregateResponseSchema
);
export const custodyWalletByIdResponse = successResponseSchema(custodyWalletByIdResponseSchema);
export const custodyDeleteWalletResponse = successResponseSchema(deleteWalletResponseSchema);
export const custodySignerCheckResponse = successResponseSchema(signerCheckResponseSchema);
export const custodySwitchOptionsResponse = successResponseSchema(
  switchProviderOptionsResponseSchema
);
export const walletApprovalRequestResponse = successResponseSchema(
  walletApprovalRequestResponseSchema
);
export const walletApprovalRequestsResponse = successResponseSchema(
  walletApprovalRequestsResponseSchema
);
export const addressScreeningResponse = successResponseSchema(addressScreeningResponseSchema);

export const allowlistEntriesResponse = successResponseSchema(allowlistEntriesResponseSchema);
export const allowlistEntryResponse = successResponseSchema(
  z.object({ entry: allowlistEntrySchema })
);

export const tokenTemplateResponse = successResponseSchema(tokenTemplateResponseSchema);
export const listTemplatesResponse = successResponseSchema(listTemplatesResponseSchema);

export const onboardingStatusResponse = successResponseSchema(onboardingStatusResponseSchema);
export const onboardingCompleteResponse = successResponseSchema(onboardingCompleteResponseSchema);
export const walletBalancesResponse = successResponseSchema(walletBalancesResponseSchema);
export const walletPolicyResponse = successResponseSchema(walletPolicyResponseSchema);
export const policyControlInventoryResponse = successResponseSchema(
  policyControlInventoryResponseSchema
);
export const walletControlProfileRevisionHistoryResponse = successResponseSchema(
  walletControlProfileRevisionHistorySchema
);
export const walletPolicyEvaluationListResponse = paginatedResponseSchema(
  walletPolicyEvaluationDetailSchema
);
export const walletPolicyEvaluationResponse = successResponseSchema(
  walletPolicyEvaluationResponseSchema
);
export const transferResponse = successResponseSchema(transferResponseSchema);
export const transferListResponse = paginatedResponseSchema(transferSchema);
export const transferBatchResponse = successResponseSchema(transferBatchResponseSchema);
export const transferBatchListResponse = paginatedResponseSchema(transferBatchSchema);
export const transferBatchEstimateResponse = successResponseSchema(
  transferBatchEstimateResponseSchema
);
export const paymentRecurringPaymentResponse = successResponseSchema(
  paymentRecurringPaymentResponseSchema
);
export const paymentRecurringPaymentCollectionResponse = successResponseSchema(
  paymentRecurringPaymentCollectionResponseSchema
);
export const paymentRecurringPaymentListResponse = successResponseSchema(
  paymentRecurringPaymentListResponseSchema
);
export const paymentSubscriptionPlanResponse = successResponseSchema(
  paymentSubscriptionPlanResponseSchema
);
export const preparePaymentSubscriptionPlanResponse = successResponseSchema(
  preparePaymentSubscriptionPlanResponseSchema
);
export const paymentSubscriptionPlanListResponse = successResponseSchema(
  paymentSubscriptionPlanListResponseSchema
);
export const paymentSubscriptionResponse = successResponseSchema(paymentSubscriptionResponseSchema);
export const preparePaymentSubscriptionAuthorizationResponse = successResponseSchema(
  preparePaymentSubscriptionAuthorizationResponseSchema
);
export const preparePaymentSubscriptionLifecycleResponse = successResponseSchema(
  preparePaymentSubscriptionLifecycleResponseSchema
);
export const paymentSubscriptionListResponse = successResponseSchema(
  paymentSubscriptionListResponseSchema
);
export const paymentSubscriptionCollectionAttemptResponse = successResponseSchema(
  paymentSubscriptionCollectionAttemptResponseSchema
);
export const preparePaymentSubscriptionCollectionResponse = successResponseSchema(
  preparePaymentSubscriptionCollectionResponseSchema
);
export const paymentSubscriptionCollectionAttemptListResponse = successResponseSchema(
  paymentSubscriptionCollectionAttemptListResponseSchema
);
export const onrampCurrenciesResponse = successResponseSchema(onrampCurrenciesResponseSchema);
export const offrampCurrenciesResponse = successResponseSchema(offrampCurrenciesResponseSchema);
export const onrampQuoteResponse = successResponseSchema(onrampQuoteResponseSchema);
export const sandboxTransferSimulationResponse = successResponseSchema(
  sandboxTransferSimulationResponseSchema
);
