package tgbot

import (
	"encoding/json"

	tgbotapi "github.com/go-telegram-bot-api/telegram-bot-api/v5"
)

func CreateChatInviteLink(botApi *tgbotapi.BotAPI, config tgbotapi.CreateChatInviteLinkConfig) (*tgbotapi.ChatInviteLink, error) {
	resp, err := botApi.Request(config)

	if err != nil {
		return nil, err
	}

	var message tgbotapi.ChatInviteLink
	err = json.Unmarshal(resp.Result, &message)
	if err != nil {
		return nil, err
	}

	return &message, nil
}

func ApproveChatJoinRequest(botApi *tgbotapi.BotAPI, config tgbotapi.ApproveChatJoinRequestConfig) error {
	resp, err := botApi.Request(config)

	if err != nil {
		return err
	}

	var message tgbotapi.Message
	err = json.Unmarshal(resp.Result, &message)
	if err != nil {
		return err
	}

	return nil
}
