// Code generated by Lark OpenAPI.

package larkauth

import (
	"context"
	"github.com/larksuite/oapi-sdk-go/v3/core"
	"net/http"
)

type V3 struct {
	AppAccessToken    *appAccessToken    // app_access_token
	AppTicket         *appTicket         // app_ticket
	TenantAccessToken *tenantAccessToken // tenant_access_token
}

func New(config *larkcore.Config) *V3 {
	return &V3{
		AppAccessToken:    &appAccessToken{config: config},
		AppTicket:         &appTicket{config: config},
		TenantAccessToken: &tenantAccessToken{config: config},
	}
}

type appAccessToken struct {
	config *larkcore.Config
}
type appTicket struct {
	config *larkcore.Config
}
type tenantAccessToken struct {
	config *larkcore.Config
}

// Create
//
// -
//
// - 官网API文档链接:https://open.feishu.cn/api-explorer?from=op_doc_tab&apiName=create&project=auth&resource=app_access_token&version=v3
//
// - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/authv3/create_appAccessToken.go
func (a *appAccessToken) Create(ctx context.Context, req *CreateAppAccessTokenReq, options ...larkcore.RequestOptionFunc) (*CreateAppAccessTokenResp, error) {
	// 发起请求
	apiReq := req.apiReq
	apiReq.ApiPath = "/open-apis/auth/v3/app_access_token"
	apiReq.HttpMethod = http.MethodPost
	apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{}
	apiResp, err := larkcore.Request(ctx, apiReq, a.config, options...)
	if err != nil {
		return nil, err
	}
	// 反序列响应结果
	resp := &CreateAppAccessTokenResp{ApiResp: apiResp}
	err = apiResp.JSONUnmarshalBody(resp, a.config)
	if err != nil {
		return nil, err
	}
	return resp, err
}

// Internal
//
// -
//
// - 官网API文档链接:https://open.feishu.cn/api-explorer?from=op_doc_tab&apiName=internal&project=auth&resource=app_access_token&version=v3
//
// - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/authv3/internal_appAccessToken.go
func (a *appAccessToken) Internal(ctx context.Context, req *InternalAppAccessTokenReq, options ...larkcore.RequestOptionFunc) (*InternalAppAccessTokenResp, error) {
	// 发起请求
	apiReq := req.apiReq
	apiReq.ApiPath = "/open-apis/auth/v3/app_access_token/internal"
	apiReq.HttpMethod = http.MethodPost
	apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{}
	apiResp, err := larkcore.Request(ctx, apiReq, a.config, options...)
	if err != nil {
		return nil, err
	}
	// 反序列响应结果
	resp := &InternalAppAccessTokenResp{ApiResp: apiResp}
	err = apiResp.JSONUnmarshalBody(resp, a.config)
	if err != nil {
		return nil, err
	}
	return resp, err
}

// Resend
//
// -
//
// - 官网API文档链接:https://open.feishu.cn/api-explorer?from=op_doc_tab&apiName=resend&project=auth&resource=app_ticket&version=v3
//
// - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/authv3/resend_appTicket.go
func (a *appTicket) Resend(ctx context.Context, req *ResendAppTicketReq, options ...larkcore.RequestOptionFunc) (*ResendAppTicketResp, error) {
	// 发起请求
	apiReq := req.apiReq
	apiReq.ApiPath = "/open-apis/auth/v3/app_ticket/resend"
	apiReq.HttpMethod = http.MethodPost
	apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{}
	apiResp, err := larkcore.Request(ctx, apiReq, a.config, options...)
	if err != nil {
		return nil, err
	}
	// 反序列响应结果
	resp := &ResendAppTicketResp{ApiResp: apiResp}
	err = apiResp.JSONUnmarshalBody(resp, a.config)
	if err != nil {
		return nil, err
	}
	return resp, err
}

// Create
//
// -
//
// - 官网API文档链接:https://open.feishu.cn/api-explorer?from=op_doc_tab&apiName=create&project=auth&resource=tenant_access_token&version=v3
//
// - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/authv3/create_tenantAccessToken.go
func (t *tenantAccessToken) Create(ctx context.Context, req *CreateTenantAccessTokenReq, options ...larkcore.RequestOptionFunc) (*CreateTenantAccessTokenResp, error) {
	// 发起请求
	apiReq := req.apiReq
	apiReq.ApiPath = "/open-apis/auth/v3/tenant_access_token"
	apiReq.HttpMethod = http.MethodPost
	apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{}
	apiResp, err := larkcore.Request(ctx, apiReq, t.config, options...)
	if err != nil {
		return nil, err
	}
	// 反序列响应结果
	resp := &CreateTenantAccessTokenResp{ApiResp: apiResp}
	err = apiResp.JSONUnmarshalBody(resp, t.config)
	if err != nil {
		return nil, err
	}
	return resp, err
}

// Internal
//
// -
//
// - 官网API文档链接:https://open.feishu.cn/api-explorer?from=op_doc_tab&apiName=internal&project=auth&resource=tenant_access_token&version=v3
//
// - 使用Demo链接:https://github.com/larksuite/oapi-sdk-go/tree/v3_main/sample/apiall/authv3/internal_tenantAccessToken.go
func (t *tenantAccessToken) Internal(ctx context.Context, req *InternalTenantAccessTokenReq, options ...larkcore.RequestOptionFunc) (*InternalTenantAccessTokenResp, error) {
	// 发起请求
	apiReq := req.apiReq
	apiReq.ApiPath = "/open-apis/auth/v3/tenant_access_token/internal"
	apiReq.HttpMethod = http.MethodPost
	apiReq.SupportedAccessTokenTypes = []larkcore.AccessTokenType{}
	apiResp, err := larkcore.Request(ctx, apiReq, t.config, options...)
	if err != nil {
		return nil, err
	}
	// 反序列响应结果
	resp := &InternalTenantAccessTokenResp{ApiResp: apiResp}
	err = apiResp.JSONUnmarshalBody(resp, t.config)
	if err != nil {
		return nil, err
	}
	return resp, err
}
