// Copyright 2013 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 (
	
	
)

// Key represents a public SSH key used to authenticate a user or deploy script.
type Key struct {
	ID        *int64     `json:"id,omitempty"`
	Key       *string    `json:"key,omitempty"`
	URL       *string    `json:"url,omitempty"`
	Title     *string    `json:"title,omitempty"`
	ReadOnly  *bool      `json:"read_only,omitempty"`
	Verified  *bool      `json:"verified,omitempty"`
	CreatedAt *Timestamp `json:"created_at,omitempty"`
	AddedBy   *string    `json:"added_by,omitempty"`
	LastUsed  *Timestamp `json:"last_used,omitempty"`
}

func ( Key) () string {
	return Stringify()
}

// ListKeys lists the verified public keys for a user. Passing the empty
// string will fetch keys for the authenticated user.
//
// GitHub API docs: https://docs.github.com/rest/users/keys#list-public-keys-for-a-user
// GitHub API docs: https://docs.github.com/rest/users/keys#list-public-ssh-keys-for-the-authenticated-user
//
//meta:operation GET /user/keys
//meta:operation GET /users/{username}/keys
func ( *UsersService) ( context.Context,  string,  *ListOptions) ([]*Key, *Response, error) {
	var  string
	if  != "" {
		 = fmt.Sprintf("users/%v/keys", )
	} else {
		 = "user/keys"
	}
	,  := addOptions(, )
	if  != nil {
		return nil, nil, 
	}

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

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

	return , , nil
}

// GetKey fetches a single public key.
//
// GitHub API docs: https://docs.github.com/rest/users/keys#get-a-public-ssh-key-for-the-authenticated-user
//
//meta:operation GET /user/keys/{key_id}
func ( *UsersService) ( context.Context,  int64) (*Key, *Response, error) {
	 := fmt.Sprintf("user/keys/%v", )

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

	 := new(Key)
	,  := .client.Do(, , )
	if  != nil {
		return nil, , 
	}

	return , , nil
}

// CreateKey adds a public key for the authenticated user.
//
// GitHub API docs: https://docs.github.com/rest/users/keys#create-a-public-ssh-key-for-the-authenticated-user
//
//meta:operation POST /user/keys
func ( *UsersService) ( context.Context,  *Key) (*Key, *Response, error) {
	 := "user/keys"

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

	 := new(Key)
	,  := .client.Do(, , )
	if  != nil {
		return nil, , 
	}

	return , , nil
}

// DeleteKey deletes a public key.
//
// GitHub API docs: https://docs.github.com/rest/users/keys#delete-a-public-ssh-key-for-the-authenticated-user
//
//meta:operation DELETE /user/keys/{key_id}
func ( *UsersService) ( context.Context,  int64) (*Response, error) {
	 := fmt.Sprintf("user/keys/%v", )

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

	return .client.Do(, , nil)
}