// Code generated by https://github.com/gagliardetto/anchor-go. DO NOT EDIT.
// This file contains parsers for the accounts defined in the IDL.

package signer_registry_solana

import (
	"fmt"
	binary "github.com/gagliardetto/binary"
)

func ParseAnyAccount(accountData []byte) (any, error) {
	decoder := binary.NewBorshDecoder(accountData)
	discriminator, err := decoder.ReadDiscriminator()
	if err != nil {
		return nil, fmt.Errorf("failed to peek account discriminator: %w", err)
	}
	switch discriminator {
	case Account_Config:
		value := new(Config)
		err := value.UnmarshalWithDecoder(decoder)
		if err != nil {
			return nil, fmt.Errorf("failed to unmarshal account as Config: %w", err)
		}
		return value, nil
	case Account_Signers:
		value := new(Signers)
		err := value.UnmarshalWithDecoder(decoder)
		if err != nil {
			return nil, fmt.Errorf("failed to unmarshal account as Signers: %w", err)
		}
		return value, nil
	default:
		return nil, fmt.Errorf("unknown discriminator: %s", binary.FormatDiscriminator(discriminator))
	}
}

func ParseAccount_Config(accountData []byte) (*Config, error) {
	decoder := binary.NewBorshDecoder(accountData)
	discriminator, err := decoder.ReadDiscriminator()
	if err != nil {
		return nil, fmt.Errorf("failed to peek discriminator: %w", err)
	}
	if discriminator != Account_Config {
		return nil, fmt.Errorf("expected discriminator %v, got %s", Account_Config, binary.FormatDiscriminator(discriminator))
	}
	acc := new(Config)
	err = acc.UnmarshalWithDecoder(decoder)
	if err != nil {
		return nil, fmt.Errorf("failed to unmarshal account of type Config: %w", err)
	}
	return acc, nil
}

func ParseAccount_Signers(accountData []byte) (*Signers, error) {
	decoder := binary.NewBorshDecoder(accountData)
	discriminator, err := decoder.ReadDiscriminator()
	if err != nil {
		return nil, fmt.Errorf("failed to peek discriminator: %w", err)
	}
	if discriminator != Account_Signers {
		return nil, fmt.Errorf("expected discriminator %v, got %s", Account_Signers, binary.FormatDiscriminator(discriminator))
	}
	acc := new(Signers)
	err = acc.UnmarshalWithDecoder(decoder)
	if err != nil {
		return nil, fmt.Errorf("failed to unmarshal account of type Signers: %w", err)
	}
	return acc, nil
}
