/** * This code was AUTOGENERATED using the Codama library. * Please DO NOT EDIT THIS FILE, instead use visitors * to add features, then rerun Codama to update it. * * @see https://github.com/codama-idl/codama */ import { combineCodec, getDiscriminatedUnionDecoder, getDiscriminatedUnionEncoder, getStructDecoder, getStructEncoder, getTupleDecoder, getTupleEncoder, type Codec, type Decoder, type Encoder, type GetDiscriminatedUnionVariant, type GetDiscriminatedUnionVariantContent, } from '@solana/kit'; import { getAsteroidDecoder, getAsteroidEncoder, getPlanetDecoder, getPlanetEncoder, type Asteroid, type AsteroidArgs, type Planet, type PlanetArgs, } from '.'; /** Represents different types a `CelestialBody` could be */ export type CelestialBodyType = | { __kind: 'Planet'; fields: readonly [Planet] } | { __kind: 'Asteroid'; fields: readonly [Asteroid] }; export type CelestialBodyTypeArgs = | { __kind: 'Planet'; fields: readonly [PlanetArgs] } | { __kind: 'Asteroid'; fields: readonly [AsteroidArgs] }; export function getCelestialBodyTypeEncoder(): Encoder { return getDiscriminatedUnionEncoder([ [ 'Planet', getStructEncoder([['fields', getTupleEncoder([getPlanetEncoder()])]]), ], [ 'Asteroid', getStructEncoder([['fields', getTupleEncoder([getAsteroidEncoder()])]]), ], ]); } export function getCelestialBodyTypeDecoder(): Decoder { return getDiscriminatedUnionDecoder([ [ 'Planet', getStructDecoder([['fields', getTupleDecoder([getPlanetDecoder()])]]), ], [ 'Asteroid', getStructDecoder([['fields', getTupleDecoder([getAsteroidDecoder()])]]), ], ]); } export function getCelestialBodyTypeCodec(): Codec< CelestialBodyTypeArgs, CelestialBodyType > { return combineCodec( getCelestialBodyTypeEncoder(), getCelestialBodyTypeDecoder(), ); } // Data Enum Helpers. export function celestialBodyType( kind: 'Planet', data: GetDiscriminatedUnionVariantContent< CelestialBodyTypeArgs, '__kind', 'Planet' >['fields'], ): GetDiscriminatedUnionVariant; export function celestialBodyType( kind: 'Asteroid', data: GetDiscriminatedUnionVariantContent< CelestialBodyTypeArgs, '__kind', 'Asteroid' >['fields'], ): GetDiscriminatedUnionVariant; export function celestialBodyType< K extends CelestialBodyTypeArgs['__kind'], Data, >(kind: K, data?: Data) { return Array.isArray(data) ? { __kind: kind, fields: data } : { __kind: kind, ...(data ?? {}) }; } export function isCelestialBodyType( kind: K, value: CelestialBodyType, ): value is CelestialBodyType & { __kind: K } { return value.__kind === kind; }