// Copyright 2016 The go-github AUTHORS. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package github

import (
	
	
)

// GPGKey represents a GitHub user's public GPG key used to verify GPG signed commits and tags.
//
// https://developer.github.com/changes/2016-04-04-git-signing-api-preview/
type GPGKey struct {
	ID                *int64      `json:"id,omitempty"`
	PrimaryKeyID      *int64      `json:"primary_key_id,omitempty"`
	KeyID             *string     `json:"key_id,omitempty"`
	RawKey            *string     `json:"raw_key,omitempty"`
	PublicKey         *string     `json:"public_key,omitempty"`
	Emails            []*GPGEmail `json:"emails,omitempty"`
	Subkeys           []*GPGKey   `json:"subkeys,omitempty"`
	CanSign           *bool       `json:"can_sign,omitempty"`
	CanEncryptComms   *bool       `json:"can_encrypt_comms,omitempty"`
	CanEncryptStorage *bool       `json:"can_encrypt_storage,omitempty"`
	CanCertify        *bool       `json:"can_certify,omitempty"`
	CreatedAt         *Timestamp  `json:"created_at,omitempty"`
	ExpiresAt         *Timestamp  `json:"expires_at,omitempty"`
}

// String stringifies a GPGKey.
func ( GPGKey) () string {
	return Stringify()
}

// GPGEmail represents an email address associated to a GPG key.
type GPGEmail struct {
	Email    *string `json:"email,omitempty"`
	Verified *bool   `json:"verified,omitempty"`
}

// ListGPGKeys lists the public GPG keys for a user. Passing the empty
// string will fetch keys for the authenticated user. It requires authentication
// via Basic Auth or via OAuth with at least read:gpg_key scope.
//
// GitHub API docs: https://docs.github.com/rest/users/gpg-keys#list-gpg-keys-for-a-user
// GitHub API docs: https://docs.github.com/rest/users/gpg-keys#list-gpg-keys-for-the-authenticated-user
//
//meta:operation GET /user/gpg_keys
//meta:operation GET /users/{username}/gpg_keys
func ( *UsersService) ( context.Context,  string,  *ListOptions) ([]*GPGKey, *Response, error) {
	var  string
	if  != "" {
		 = fmt.Sprintf("users/%v/gpg_keys", )
	} else {
		 = "user/gpg_keys"
	}
	,  := addOptions(, )
	if  != nil {
		return nil, nil, 
	}

	,  := .client.NewRequest("GET", , nil)
	if  != nil {
		return nil, nil, 
	}

	var  []*GPGKey
	,  := .client.Do(, , &)
	if  != nil {
		return nil, , 
	}

	return , , nil
}

// GetGPGKey gets extended details for a single GPG key. It requires authentication
// via Basic Auth or via OAuth with at least read:gpg_key scope.
//
// GitHub API docs: https://docs.github.com/rest/users/gpg-keys#get-a-gpg-key-for-the-authenticated-user
//
//meta:operation GET /user/gpg_keys/{gpg_key_id}
func ( *UsersService) ( context.Context,  int64) (*GPGKey, *Response, error) {
	 := fmt.Sprintf("user/gpg_keys/%v", )
	,  := .client.NewRequest("GET", , nil)
	if  != nil {
		return nil, nil, 
	}

	 := &GPGKey{}
	,  := .client.Do(, , )
	if  != nil {
		return nil, , 
	}

	return , , nil
}

// CreateGPGKey creates a GPG key. It requires authentication via Basic Auth
// or OAuth with at least write:gpg_key scope.
//
// GitHub API docs: https://docs.github.com/rest/users/gpg-keys#create-a-gpg-key-for-the-authenticated-user
//
//meta:operation POST /user/gpg_keys
func ( *UsersService) ( context.Context,  string) (*GPGKey, *Response, error) {
	 := &struct {
		 string `json:"armored_public_key"`
	}{: }
	,  := .client.NewRequest("POST", "user/gpg_keys", )
	if  != nil {
		return nil, nil, 
	}

	 := &GPGKey{}
	,  := .client.Do(, , )
	if  != nil {
		return nil, , 
	}

	return , , nil
}

// DeleteGPGKey deletes a GPG key. It requires authentication via Basic Auth or
// via OAuth with at least admin:gpg_key scope.
//
// GitHub API docs: https://docs.github.com/rest/users/gpg-keys#delete-a-gpg-key-for-the-authenticated-user
//
//meta:operation DELETE /user/gpg_keys/{gpg_key_id}
func ( *UsersService) ( context.Context,  int64) (*Response, error) {
	 := fmt.Sprintf("user/gpg_keys/%v", )
	,  := .client.NewRequest("DELETE", , nil)
	if  != nil {
		return nil, 
	}

	return .client.Do(, , nil)
}