/*
 * 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 { Result as SafeParseResult } from "../../types/fp.js";
import { SDKValidationError } from "../errors/sdkvalidationerror.js";
import {
  BenefitGitHubRepositoryProperties,
  BenefitGitHubRepositoryProperties$inboundSchema,
  BenefitGitHubRepositoryProperties$Outbound,
  BenefitGitHubRepositoryProperties$outboundSchema,
} from "./benefitgithubrepositoryproperties.js";
import {
  BenefitVisibility,
  BenefitVisibility$inboundSchema,
  BenefitVisibility$outboundSchema,
} from "./benefitvisibility.js";
import {
  MetadataOutputType,
  MetadataOutputType$inboundSchema,
  MetadataOutputType$Outbound,
  MetadataOutputType$outboundSchema,
} from "./metadataoutputtype.js";

/**
 * A benefit of type `github_repository`.
 *
 * @remarks
 *
 * Use it to automatically invite your backers to a private GitHub repository.
 */
export type BenefitGitHubRepository = {
  /**
   * The ID of the benefit.
   */
  id: string;
  /**
   * Creation timestamp of the object.
   */
  createdAt: Date;
  /**
   * Last modification timestamp of the object.
   */
  modifiedAt: Date | null;
  type: "github_repository";
  /**
   * The description of the benefit.
   */
  description: string;
  /**
   * Whether the benefit is selectable when creating a product.
   */
  selectable: boolean;
  /**
   * Whether the benefit is deletable.
   */
  deletable: boolean;
  /**
   * Whether the benefit is deleted.
   */
  isDeleted: boolean;
  /**
   * The ID of the organization owning the benefit.
   */
  organizationId: string;
  metadata: { [k: string]: MetadataOutputType };
  visibility: BenefitVisibility;
  /**
   * Properties for a benefit of type `github_repository`.
   */
  properties: BenefitGitHubRepositoryProperties;
  visibilityConfigurable: boolean;
};

/** @internal */
export const BenefitGitHubRepository$inboundSchema: z.ZodMiniType<
  BenefitGitHubRepository,
  unknown
> = z.pipe(
  z.object({
    id: z.string(),
    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))),
    ),
    type: z.literal("github_repository"),
    description: z.string(),
    selectable: z.boolean(),
    deletable: z.boolean(),
    is_deleted: z.boolean(),
    organization_id: z.string(),
    metadata: z.record(z.string(), MetadataOutputType$inboundSchema),
    visibility: BenefitVisibility$inboundSchema,
    properties: BenefitGitHubRepositoryProperties$inboundSchema,
    visibility_configurable: z.boolean(),
  }),
  z.transform((v) => {
    return remap$(v, {
      "created_at": "createdAt",
      "modified_at": "modifiedAt",
      "is_deleted": "isDeleted",
      "organization_id": "organizationId",
      "visibility_configurable": "visibilityConfigurable",
    });
  }),
);
/** @internal */
export type BenefitGitHubRepository$Outbound = {
  id: string;
  created_at: string;
  modified_at: string | null;
  type: "github_repository";
  description: string;
  selectable: boolean;
  deletable: boolean;
  is_deleted: boolean;
  organization_id: string;
  metadata: { [k: string]: MetadataOutputType$Outbound };
  visibility: string;
  properties: BenefitGitHubRepositoryProperties$Outbound;
  visibility_configurable: boolean;
};

/** @internal */
export const BenefitGitHubRepository$outboundSchema: z.ZodMiniType<
  BenefitGitHubRepository$Outbound,
  BenefitGitHubRepository
> = z.pipe(
  z.object({
    id: z.string(),
    createdAt: z.pipe(z.date(), z.transform(v => v.toISOString())),
    modifiedAt: z.nullable(z.pipe(z.date(), z.transform(v => v.toISOString()))),
    type: z.literal("github_repository"),
    description: z.string(),
    selectable: z.boolean(),
    deletable: z.boolean(),
    isDeleted: z.boolean(),
    organizationId: z.string(),
    metadata: z.record(z.string(), MetadataOutputType$outboundSchema),
    visibility: BenefitVisibility$outboundSchema,
    properties: BenefitGitHubRepositoryProperties$outboundSchema,
    visibilityConfigurable: z.boolean(),
  }),
  z.transform((v) => {
    return remap$(v, {
      createdAt: "created_at",
      modifiedAt: "modified_at",
      isDeleted: "is_deleted",
      organizationId: "organization_id",
      visibilityConfigurable: "visibility_configurable",
    });
  }),
);

export function benefitGitHubRepositoryToJSON(
  benefitGitHubRepository: BenefitGitHubRepository,
): string {
  return JSON.stringify(
    BenefitGitHubRepository$outboundSchema.parse(benefitGitHubRepository),
  );
}
export function benefitGitHubRepositoryFromJSON(
  jsonString: string,
): SafeParseResult<BenefitGitHubRepository, SDKValidationError> {
  return safeParse(
    jsonString,
    (x) => BenefitGitHubRepository$inboundSchema.parse(JSON.parse(x)),
    `Failed to parse 'BenefitGitHubRepository' from JSON`,
  );
}
