package gitlab

import "net/http"

type (
	MarkdownServiceInterface interface {
		Render(opt *RenderOptions, options ...RequestOptionFunc) (*Markdown, *Response, error)
	}

	// MarkdownService handles communication with the markdown related methods of
	// the GitLab API.
	//
	// GitLab API docs: https://docs.gitlab.com/api/markdown/
	MarkdownService struct {
		client *Client
	}
)

var _ MarkdownServiceInterface = (*MarkdownService)(nil)

// Markdown represents a markdown document.
//
// GitLab API docs: https://docs.gitlab.com/api/markdown/
type Markdown struct {
	HTML string `json:"html"`
}

// RenderOptions represents the available Render() options.
//
// GitLab API docs:
// https://docs.gitlab.com/api/markdown/#render-an-arbitrary-markdown-document
type RenderOptions struct {
	Text                    *string `url:"text,omitempty" json:"text,omitempty"`
	GitlabFlavouredMarkdown *bool   `url:"gfm,omitempty" json:"gfm,omitempty"`
	Project                 *string `url:"project,omitempty" json:"project,omitempty"`
}

// Render an arbitrary markdown document.
//
// GitLab API docs:
// https://docs.gitlab.com/api/markdown/#render-an-arbitrary-markdown-document
func (s *MarkdownService) Render(opt *RenderOptions, options ...RequestOptionFunc) (*Markdown, *Response, error) {
	return do[*Markdown](s.client,
		withMethod(http.MethodPost),
		withPath("markdown"),
		withAPIOpts(opt),
		withRequestOpts(options...),
	)
}
