package apirequest

import (
	"fmt"
	"net/http"

	"codeberg.org/vlbeaudoin/voki"
	"codeberg.org/vlbeaudoin/voki/request"
	"git.agecem.com/agecem/agecem-org/apiresponse"
)

var _ request.Requester[apiresponse.V1BucketsGET] = V1BucketsGET{}

type V1BucketsGET struct{}

func NewV1BucketsGET() (request V1BucketsGET, err error) {
	return
}

func (request V1BucketsGET) Complete() bool { return true }

func (request V1BucketsGET) Request(v *voki.Voki) (response apiresponse.V1BucketsGET, err error) {
	if !request.Complete() {
		err = fmt.Errorf("Incomplete V1BucketsGET request")
		return
	}

	return response, v.UnmarshalIfComplete(http.MethodGet, "/v1/bucket", nil, true, &response)
}

var _ request.Requester[apiresponse.V1BucketGET] = V1BucketGET{}

type V1BucketGET struct {
	Params struct {
		Bucket string `json:"bucket"`
	}
}

func NewV1BucketGET(bucket string) (request V1BucketGET, err error) {
	if bucket == "" {
		err = fmt.Errorf("NewV1BucketGET requires non-nil bucket name")
	}

	request.Params.Bucket = bucket

	return
}

func (request V1BucketGET) Complete() bool { return request.Params.Bucket != "" }

func (request V1BucketGET) Request(v *voki.Voki) (response apiresponse.V1BucketGET, err error) {
	if !request.Complete() {
		err = fmt.Errorf("Incomplete V1BucketGET request")
		return
	}

	return response, v.UnmarshalIfComplete(http.MethodGet, fmt.Sprintf("/v1/bucket/%s", request.Params.Bucket), nil, true, &response)
}
