package mytypes

import (
	"github.com/ceph/go-ceph/rados"
	"github.com/ceph/go-ceph/rbd"
	"github.com/prometheus/client_golang/prometheus"
)

type Params struct {
	Config  string
	Keyring string
}

type CephConnector interface {
	ListPools() ([]string,error)
	OpenIOContext(poolName string) (IOContexter, error)
}

type CephConnection struct {
	Conn *rados.Conn
}

// Here I do implement CephConnector interface
func (cc CephConnection) ListPools() ([]string,error) {
	return cc.Conn.ListPools()
}

// Here I do implement CephConnector interface
func (cc CephConnection) OpenIOContext(poolName string) (IOContexter,error) {
	ioctx,err := cc.Conn.OpenIOContext(poolName)
	if err != nil {
		return nil,err
	}
	return IOContextWrapper{ioctx: ioctx},nil
}


type IOContexter interface {
	Destroy()
	GetImageNames() ([]string, error)
	GetImage(name string) RBDImager
}

type IOContextWrapper struct {
	ioctx *rados.IOContext
}

func (iocw IOContextWrapper) Destroy() {
	iocw.ioctx.Destroy()
}

func (iocw IOContextWrapper) GetImageNames() ([]string,error){
	return rbd.GetImageNames(iocw.ioctx)
}

func (iocw IOContextWrapper) GetImage(rbdName string) RBDImager {
	img := rbd.GetImage(iocw.ioctx,rbdName)
	return RBDImageWrapper{image: img}
}


type RBDImager interface {
	Open() error
	Close() error
	Stat() (*rbd.ImageInfo,error)
}

type RBDImageWrapper struct {
	image *rbd.Image
}

func (riw RBDImageWrapper) Open() error {
	return riw.image.Open()
}

func (riw RBDImageWrapper) Close() error {
	return riw.image.Close()
}

func (riw RBDImageWrapper) Stat() (*rbd.ImageInfo,error) {
	return riw.image.Stat()
}

type IRBD interface {
	GetName() string
	GetSize() uint64
}

type RBDUsage struct {
	Images []RBD 
}

type RBD struct {
	Name          string 
	rbd.ImageInfo
}

func (r RBD) GetName() string {
	return r.Name
}

func (r RBD) GetSize() uint64 {
	return r.Size
}

type Pool struct {
	Name    string
	HasRBD bool
	RBDlist []IRBD
}

type Metrics struct {
	TotalRbdRequestedSizePerPool *prometheus.GaugeVec
	// Total_rbd_requested_size prometheus.Gauge
}
