// Code generated by protoc-gen-volcengine-sdk
// source: RecordManageService
// DO NOT EDIT!

package live

import (
	"encoding/json"
	"fmt"
	"net/http"
	"net/url"

	"google.golang.org/protobuf/encoding/protojson"

	"github.com/pkg/errors"

	"github.com/volcengine/volc-sdk-golang/service/live/models/request"
	"github.com/volcengine/volc-sdk-golang/service/live/models/response"
)

// DescribeRecordTaskFileHistory
/*
 * @param *request.DescribeRecordTaskFileHistoryRequest
 * @return *response.DescribeRecordTaskFileHistoryResponse, int, error
 */
func (p *LIVE) DescribeRecordTaskFileHistory(req *request.DescribeRecordTaskFileHistoryRequest) (*response.DescribeRecordTaskFileHistoryResponse, int, error) {
	body, err := json.Marshal(req)
	if err != nil {
		return nil, http.StatusBadRequest, err
	}
	respBody, status, err := p.Json("DescribeRecordTaskFileHistory", url.Values{}, string(body))
	fmt.Printf("respBody%#v\n", string(respBody))
	output := &response.DescribeRecordTaskFileHistoryResponse{}
	unmarshaler := protojson.UnmarshalOptions{
		DiscardUnknown: true,
	}
	errUnmarshal := unmarshaler.Unmarshal(respBody, output)
	fmt.Printf("output%#v\n", output)

	if err != nil || status != http.StatusOK {
		// if exist http err,check whether the respBody's type is defined struct,
		// if it is ,
		// return struct,
		// otherwise return nil body
		// if httpCode is not 200,check whether the respBody's type is defined struct,
		// if it is ,
		// use errorCode as err and return struct,
		// otherwise use respBody string as error and return
		if errUnmarshal != nil || len(output.GetResponseMetadata().GetError().GetCode()) == 0 {
			if err == nil {
				err = errors.New(string(respBody))
			}
			return nil, status, err
		} else {
			return output, status, errors.New(output.GetResponseMetadata().GetError().GetCode())
		}
	}
	return output, status, nil
}
