1package storage
2
3import (
4	liquidweb "github.com/liquidweb/liquidweb-go"
5)
6
7// BlockVolumeBackend describes the interface for interactions with the API.
8type BlockVolumeBackend interface {
9	Create(*BlockVolumeParams) (*BlockVolume, error)
10	Details(string) (*BlockVolume, error)
11	List(*BlockVolumeParams) (*BlockVolumeList, error)
12	Update(*BlockVolumeParams) (*BlockVolume, error)
13	Delete(string) (*BlockVolumeDeletion, error)
14	Resize(*BlockVolumeParams) (*BlockVolumeResize, error)
15}
16
17// BlockVolumeClient is the backend implementation for interacting with block volumes.
18type BlockVolumeClient struct {
19	Backend liquidweb.Backend
20}
21
22// Create creates a new block volume.
23func (c *BlockVolumeClient) Create(params *BlockVolumeParams) (*BlockVolume, error) {
24	var result BlockVolume
25	err := c.Backend.CallIntoInterface("v1/Storage/Block/Volume/create", params, &result)
26	if err != nil {
27		return nil, err
28	}
29
30	return &result, nil
31}
32
33// Details returns details about a block volume.
34func (c *BlockVolumeClient) Details(id string) (*BlockVolume, error) {
35	var result BlockVolume
36	params := BlockVolumeParams{UniqID: id}
37
38	err := c.Backend.CallIntoInterface("v1/Storage/Block/Volume/details", params, &result)
39	if err != nil {
40		return nil, err
41	}
42	return &result, nil
43}
44
45// List returns a list of block volumes.
46func (c *BlockVolumeClient) List(params *BlockVolumeParams) (*BlockVolumeList, error) {
47	list := &BlockVolumeList{}
48
49	err := c.Backend.CallIntoInterface("v1/Storage/Block/Volume/list", params, list)
50	if err != nil {
51		return nil, err
52	}
53	return list, nil
54}
55
56// Update will update a block volume.
57func (c *BlockVolumeClient) Update(params *BlockVolumeParams) (*BlockVolume, error) {
58	var result BlockVolume
59	err := c.Backend.CallIntoInterface("v1/Storage/Block/Volume/update", params, &result)
60	if err != nil {
61		return nil, err
62	}
63	return &result, nil
64}
65
66// Delete will delete a block volume.
67func (c *BlockVolumeClient) Delete(id string) (*BlockVolumeDeletion, error) {
68	var result BlockVolumeDeletion
69	params := BlockVolumeParams{UniqID: id}
70
71	err := c.Backend.CallIntoInterface("v1/Storage/Block/Volume/delete", params, &result)
72	if err != nil {
73		return nil, err
74	}
75	return &result, nil
76}
77
78// Resize will resize a block volume.
79func (c *BlockVolumeClient) Resize(params *BlockVolumeParams) (*BlockVolumeResize, error) {
80	var result BlockVolumeResize
81	err := c.Backend.CallIntoInterface("v1/Storage/Block/Volume/resize", params, &result)
82	if err != nil {
83		return nil, err
84	}
85	return &result, nil
86}
87