package pcidevice

import (
	"context"
	"net/http"
	"strconv"

	"repository.basistech.ru/BASIS/decort-golang-sdk/internal/constants"
	"repository.basistech.ru/BASIS/decort-golang-sdk/internal/validators"
)

// AccessRevoke struct to revoke access from a PCI device
type AccessRevokeRequest struct {
	DeviceID   uint64   `url:"device_id"    json:"device_id" validate:"required"`
	AccountIDs []uint64 `url:"account_ids"  json:"account_ids" validate:"required"`
}

// AccessRevoke revokes access from a PCI device
func (p PCIDevice) AccessRevoke(ctx context.Context, req AccessRevokeRequest) (bool, error) {
	err := validators.ValidateRequest(req)
	if err != nil {
		return false, validators.ValidationErrors(validators.GetErrors(err))
	}

	url := "/cloudbroker/pcidevice/access_revoke"

	res, err := p.client.DecortApiCallCtype(ctx, http.MethodPost, url, constants.MIMEJSON, req)
	if err != nil {
		return false, err
	}

	result, err := strconv.ParseBool(string(res))
	if err != nil {
		return false, err
	}

	return result, nil
}
