package common

import (
	"time"

	"github.com/fiskerinc/cloud-services/pkg/common/dbbasemodel"
	"github.com/google/uuid"
)

const (
	Seconds string = "Seconds"
	Minutes string = "Minutes"
	Hours   string = "Hours"
	Days    string = "Days"
)

type SubscriptionType struct {
	ID            uuid.UUID `json:"id" pg:"type:uuid,default:uuid_generate_v4()"`
	Name          string    `json:"name" validate:"required,max=256"`
	Destination   string    `json:"destination" validate:"required,max=10"`
	Price         int       `json:"price"`
	Currency      string    `json:"currency" validate:"required,max=4"`
	Description   string    `json:"description" validate:"required,max=1000"`
	DurationValue int64     `json:"duration_value"`
	DurationUnit  string    `json:"duration_unit" validate:"required,max=10"`
	dbbasemodel.DBModelBase
}

func (st *SubscriptionType) GetDuration() time.Duration {
	switch st.DurationUnit {
	case Seconds:
		return time.Duration(st.DurationValue) * time.Second
	case Minutes:
		return time.Duration(st.DurationValue) * time.Minute
	case Hours:
		return time.Duration(st.DurationValue) * time.Hour
	case Days:
		return time.Duration(st.DurationValue) * time.Hour * 24
	}

	return time.Duration(0)
}
