// Code generated by cmd/genapi. DO NOT EDIT.

//go:build !ignore_autogenerated

// Package api contains the Telegram Bot API object types and method
// wrappers, generated from the live documentation by cmd/genapi.
package api

import (
	"fmt"
	"github.com/goccy/go-json"
	"io"
)

var _ = io.Discard   // keep import even if no fields use io
var _ = json.Marshal // keep import for UnmarshalXxx helpers
var _ = fmt.Errorf   // keep import for UnmarshalXxx helpers

// This object represents a Telegram user or bot.
type User struct {
	// Unique identifier.
	ID int64 `json:"id"`
	// True, if this user is a bot.
	IsBot bool `json:"is_bot"`
	// User's or bot's first name.
	FirstName string `json:"first_name"`
	// Optional. User's or bot's last name.
	LastName string `json:"last_name,omitempty"`
}

// ChatMember is a union type. The following concrete variants implement
// it:
//   - ChatMemberOwner
//   - ChatMemberAdministrator
//
// This object contains information about one member of a chat. Currently, the following 6 types of chat members are supported:
type ChatMember interface{ isChatMember() }

// isChatMember is the marker method that makes ChatMemberOwner implement ChatMember.
func (*ChatMemberOwner) isChatMember() {}

// isChatMember is the marker method that makes ChatMemberAdministrator implement ChatMember.
func (*ChatMemberAdministrator) isChatMember() {}

// UnmarshalChatMember decodes a ChatMember from JSON by inspecting the
// "status" field and dispatching to the correct concrete type.
func UnmarshalChatMember(data []byte) (ChatMember, error) {
	var probe struct {
		V string `json:"status"`
	}
	if err := json.Unmarshal(data, &probe); err != nil {
		return nil, err
	}
	var v ChatMember
	switch probe.V {
	case "administrator":
		v = &ChatMemberAdministrator{}
	case "creator":
		v = &ChatMemberOwner{}
	case "kicked":
		v = &ChatMemberBanned{}
	case "left":
		v = &ChatMemberLeft{}
	case "member":
		v = &ChatMemberMember{}
	case "restricted":
		v = &ChatMemberRestricted{}
	default:
		return nil, fmt.Errorf("ChatMember: unknown status %q", probe.V)
	}
	if err := json.Unmarshal(data, v); err != nil {
		return nil, err
	}
	return v, nil
}
