package live_test

import (
	"testing"

	"cloud.o-forge.io/core/oc-lib/models/live"
	"cloud.o-forge.io/core/oc-lib/models/utils"
	"cloud.o-forge.io/core/oc-lib/tools"
	"github.com/stretchr/testify/assert"
)

// ---- AbstractLive (via LiveDatacenter embedding) ----

func TestAbstractLive_StoreDraftDefault(t *testing.T) {
	dc := &live.LiveDatacenter{}
	dc.StoreDraftDefault()
	assert.True(t, dc.IsDraft)
}

func TestAbstractLive_CanDelete_Draft(t *testing.T) {
	dc := &live.LiveDatacenter{}
	dc.IsDraft = true
	assert.True(t, dc.CanDelete())
}

func TestAbstractLive_CanDelete_NonDraft(t *testing.T) {
	dc := &live.LiveDatacenter{}
	dc.IsDraft = false
	assert.False(t, dc.CanDelete())
}

func TestAbstractLive_GetMonitorPath(t *testing.T) {
	dc := &live.LiveDatacenter{}
	dc.MonitorPath = "/metrics"
	assert.Equal(t, "/metrics", dc.GetMonitorPath())
}

func TestAbstractLive_GetResourcesID_Empty(t *testing.T) {
	dc := &live.LiveDatacenter{}
	assert.Empty(t, dc.GetResourcesID())
}

func TestAbstractLive_SetResourcesID_Append(t *testing.T) {
	dc := &live.LiveDatacenter{}
	dc.SetResourcesID("res-1")
	assert.Equal(t, []string{"res-1"}, dc.GetResourcesID())
}

func TestAbstractLive_SetResourcesID_NoDuplication(t *testing.T) {
	dc := &live.LiveDatacenter{}
	dc.SetResourcesID("res-1")
	dc.SetResourcesID("res-1") // second call should not duplicate
	assert.Len(t, dc.GetResourcesID(), 1)
}

func TestAbstractLive_SetResourcesID_MultipleDistinct(t *testing.T) {
	dc := &live.LiveDatacenter{}
	dc.SetResourcesID("res-1")
	dc.SetResourcesID("res-2")
	assert.Len(t, dc.GetResourcesID(), 2)
}

func TestAbstractLive_GetResourceType(t *testing.T) {
	dc := &live.LiveDatacenter{}
	assert.Equal(t, tools.INVALID, dc.GetResourceType())
}

// ---- LiveDatacenter ----

func TestLiveDatacenter_GetAccessor(t *testing.T) {
	dc := &live.LiveDatacenter{}
	acc := dc.GetAccessor(&tools.APIRequest{})
	assert.NotNil(t, acc)
}

func TestLiveDatacenter_GetAccessor_NilRequest(t *testing.T) {
	dc := &live.LiveDatacenter{}
	acc := dc.GetAccessor(nil)
	assert.NotNil(t, acc)
}

func TestLiveDatacenter_IDAndName(t *testing.T) {
	dc := &live.LiveDatacenter{}
	dc.AbstractLive.AbstractObject = utils.AbstractObject{UUID: "dc-id", Name: "dc-name"}
	assert.Equal(t, "dc-id", dc.GetID())
	assert.Equal(t, "dc-name", dc.GetName())
}

// ---- LiveStorage ----

func TestLiveStorage_StoreDraftDefault(t *testing.T) {
	s := &live.LiveStorage{}
	s.StoreDraftDefault()
	assert.True(t, s.IsDraft)
}

func TestLiveStorage_CanDelete_Draft(t *testing.T) {
	s := &live.LiveStorage{}
	s.IsDraft = true
	assert.True(t, s.CanDelete())
}

func TestLiveStorage_CanDelete_NonDraft(t *testing.T) {
	s := &live.LiveStorage{}
	s.IsDraft = false
	assert.False(t, s.CanDelete())
}

func TestLiveStorage_GetAccessor(t *testing.T) {
	s := &live.LiveStorage{}
	acc := s.GetAccessor(&tools.APIRequest{})
	assert.NotNil(t, acc)
}

func TestLiveStorage_SetResourcesID_NoDuplication(t *testing.T) {
	s := &live.LiveStorage{}
	s.SetResourcesID("storage-1")
	s.SetResourcesID("storage-1")
	assert.Len(t, s.GetResourcesID(), 1)
}
