package fenetsec

import (
	"bytes"
	"fmt"
	"io/ioutil"
	"net/http"
)

func (c *Client) FileContent(id string, options ...*FireEngineOptions) (string, error) {
	o := processOptions(options...)
	req, rqErr := c.newRequest(feAPI+fmt.Sprintf("/files/%v/content", id), http.MethodGet, o, nil)
	if rqErr != nil {
		return "", rqErr
	}
	rspReader := bytes.NewBuffer([]byte{})
	_, rErr := c.do(req, o, rspReader)
	if rErr != nil {
		return "", rErr
	}
	body, bErr := ioutil.ReadAll(rspReader)
	if bErr != nil {
		return "", bErr
	}
	return string(body), nil
}
