package commerce

import "gorm.io/gorm"

var publicHiddenInstanceStatuses = []string{
	"failed",
	"provision_failed",
	"terminated",
	"deleted",
	"cancelled",
	"canceled",
}

var ticketAttachableInstanceStatuses = []string{
	"active",
	"suspended",
}

func publicVisibleInstanceScope(db *gorm.DB) *gorm.DB {
	return db.Where("status NOT IN ?", publicHiddenInstanceStatuses)
}

func ticketAttachableInstanceScope(db *gorm.DB) *gorm.DB {
	return db.Where("status IN ?", ticketAttachableInstanceStatuses)
}

func isPublicVisibleInstanceStatus(status string) bool {
	for _, hidden := range publicHiddenInstanceStatuses {
		if status == hidden {
			return false
		}
	}
	return true
}

func isTicketAttachableInstanceStatus(status string) bool {
	for _, allowed := range ticketAttachableInstanceStatuses {
		if status == allowed {
			return true
		}
	}
	return false
}
