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

// RepositoryListForksOptions specifies the optional parameters to the
// RepositoriesService.ListForks method.
type RepositoryListForksOptions struct {
	// How to sort the forks list. Possible values are: newest, oldest,
	// watchers. Default is "newest".
	Sort string `url:"sort,omitempty"`

	ListOptions
}

// ListForks lists the forks of the specified repository.
//
// GitHub API docs: https://docs.github.com/rest/repos/forks#list-forks
//
//meta:operation GET /repos/{owner}/{repo}/forks
func ( *RepositoriesService) ( context.Context, ,  string,  *RepositoryListForksOptions) ([]*Repository, *Response, error) {
	 := fmt.Sprintf("repos/%v/%v/forks", , )
	,  := addOptions(, )
	if  != nil {
		return nil, nil, 
	}

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

	// TODO: remove custom Accept header when topics API fully launches.
	.Header.Set("Accept", mediaTypeTopicsPreview)

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

	return , , nil
}

// RepositoryCreateForkOptions specifies the optional parameters to the
// RepositoriesService.CreateFork method.
type RepositoryCreateForkOptions struct {
	// The organization to fork the repository into.
	Organization      string `json:"organization,omitempty"`
	Name              string `json:"name,omitempty"`
	DefaultBranchOnly bool   `json:"default_branch_only,omitempty"`
}

// CreateFork creates a fork of the specified repository.
//
// This method might return an *AcceptedError and a status code of
// 202. This is because this is the status that GitHub returns to signify that
// it is now computing creating the fork in a background task. In this event,
// the Repository value will be returned, which includes the details about the pending fork.
// A follow up request, after a delay of a second or so, should result
// in a successful request.
//
// GitHub API docs: https://docs.github.com/rest/repos/forks#create-a-fork
//
//meta:operation POST /repos/{owner}/{repo}/forks
func ( *RepositoriesService) ( context.Context, ,  string,  *RepositoryCreateForkOptions) (*Repository, *Response, error) {
	 := fmt.Sprintf("repos/%v/%v/forks", , )

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

	 := new(Repository)
	,  := .client.Do(, , )
	if  != nil {
		// Persist AcceptedError's metadata to the Repository object.
		if ,  := .(*AcceptedError);  {
			if  := json.Unmarshal(.Raw, );  != nil {
				return , , 
			}

			return , , 
		}
		return nil, , 
	}

	return , , nil
}