/**
 * 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 {
  addDecoderSizePrefix,
  addEncoderSizePrefix,
  combineCodec,
  getArrayDecoder,
  getArrayEncoder,
  getDiscriminatedUnionDecoder,
  getDiscriminatedUnionEncoder,
  getStructDecoder,
  getStructEncoder,
  getTupleDecoder,
  getTupleEncoder,
  getU32Decoder,
  getU32Encoder,
  getUtf8Decoder,
  getUtf8Encoder,
  type Codec,
  type Decoder,
  type Encoder,
  type GetDiscriminatedUnionVariant,
  type GetDiscriminatedUnionVariantContent,
} from '@solana/kit';

/**
 * Inner enum for the MetadataAdditionalFieldRestriction enum.
 * * Includes - The field must include one of the values in the vector.
 * * Excludes - The field must not include any of the values in the vector.
 */

export type MetadataAdditionalFieldRestriction =
  | { __kind: 'Includes'; fields: readonly [Array<string>] }
  | { __kind: 'Excludes'; fields: readonly [Array<string>] };

export type MetadataAdditionalFieldRestrictionArgs =
  MetadataAdditionalFieldRestriction;

export function getMetadataAdditionalFieldRestrictionEncoder(): Encoder<MetadataAdditionalFieldRestrictionArgs> {
  return getDiscriminatedUnionEncoder([
    [
      'Includes',
      getStructEncoder([
        [
          'fields',
          getTupleEncoder([
            getArrayEncoder(
              addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())
            ),
          ]),
        ],
      ]),
    ],
    [
      'Excludes',
      getStructEncoder([
        [
          'fields',
          getTupleEncoder([
            getArrayEncoder(
              addEncoderSizePrefix(getUtf8Encoder(), getU32Encoder())
            ),
          ]),
        ],
      ]),
    ],
  ]);
}

export function getMetadataAdditionalFieldRestrictionDecoder(): Decoder<MetadataAdditionalFieldRestriction> {
  return getDiscriminatedUnionDecoder([
    [
      'Includes',
      getStructDecoder([
        [
          'fields',
          getTupleDecoder([
            getArrayDecoder(
              addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())
            ),
          ]),
        ],
      ]),
    ],
    [
      'Excludes',
      getStructDecoder([
        [
          'fields',
          getTupleDecoder([
            getArrayDecoder(
              addDecoderSizePrefix(getUtf8Decoder(), getU32Decoder())
            ),
          ]),
        ],
      ]),
    ],
  ]);
}

export function getMetadataAdditionalFieldRestrictionCodec(): Codec<
  MetadataAdditionalFieldRestrictionArgs,
  MetadataAdditionalFieldRestriction
> {
  return combineCodec(
    getMetadataAdditionalFieldRestrictionEncoder(),
    getMetadataAdditionalFieldRestrictionDecoder()
  );
}

// Data Enum Helpers.
export function metadataAdditionalFieldRestriction(
  kind: 'Includes',
  data: GetDiscriminatedUnionVariantContent<
    MetadataAdditionalFieldRestrictionArgs,
    '__kind',
    'Includes'
  >['fields']
): GetDiscriminatedUnionVariant<
  MetadataAdditionalFieldRestrictionArgs,
  '__kind',
  'Includes'
>;
export function metadataAdditionalFieldRestriction(
  kind: 'Excludes',
  data: GetDiscriminatedUnionVariantContent<
    MetadataAdditionalFieldRestrictionArgs,
    '__kind',
    'Excludes'
  >['fields']
): GetDiscriminatedUnionVariant<
  MetadataAdditionalFieldRestrictionArgs,
  '__kind',
  'Excludes'
>;
export function metadataAdditionalFieldRestriction<
  K extends MetadataAdditionalFieldRestrictionArgs['__kind'],
  Data,
>(kind: K, data?: Data) {
  return Array.isArray(data)
    ? { __kind: kind, fields: data }
    : { __kind: kind, ...(data ?? {}) };
}

export function isMetadataAdditionalFieldRestriction<
  K extends MetadataAdditionalFieldRestriction['__kind'],
>(
  kind: K,
  value: MetadataAdditionalFieldRestriction
): value is MetadataAdditionalFieldRestriction & { __kind: K } {
  return value.__kind === kind;
}
