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

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

/** @internal */
export const GithubRepositoryOut$inboundSchema: z.ZodType<
  GithubRepositoryOut,
  z.ZodTypeDef,
  unknown
> = z.object({
  type: z.literal("github").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`,
  );
}
