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

import * as z from "zod/v3";
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 { SDKValidationError } from "../errors/sdkvalidationerror.js";

export const GithubRepositoryOutType = {
  Github: "github",
} as const;
export type GithubRepositoryOutType = ClosedEnum<
  typeof GithubRepositoryOutType
>;

export type GithubRepositoryOut = {
  type: GithubRepositoryOutType | undefined;
  name: string;
  owner: string;
  ref?: string | null | undefined;
  weight: number | undefined;
  commitId: string;
};

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

/** @internal */
export const GithubRepositoryOut$inboundSchema: z.ZodType<
  GithubRepositoryOut,
  z.ZodTypeDef,
  unknown
> = z.object({
  type: GithubRepositoryOutType$inboundSchema.default("github"),
  name: z.string(),
  owner: z.string(),
  ref: z.nullable(z.string()).optional(),
  weight: z.number().default(1),
  commit_id: z.string(),
}).transform((v) => {
  return remap$(v, {
    "commit_id": "commitId",
  });
});

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