package dto

import (
	"errors"
	"time"

	"quyun/v2/app/requests"
	"quyun/v2/database/models"
)

type TenantFilter struct {
	requests.Pagination
	requests.SortQueryFilter

	Name *string `json:"name,omitempty" query:"name"`
}

type TenantItem struct {
	*models.Tenant

	UserCount         int64  `json:"user_count"`
	UserBalance       int64  `json:"user_balance"`
	StatusDescription string `json:"status_description"`
}

type TenantExpireUpdateForm struct {
	Duration int `json:"duration" validate:"required,oneof=7 30 90 180 365"`
}

// Duration
func (form *TenantExpireUpdateForm) ParseDuration() (time.Duration, error) {
	duration := time.Duration(form.Duration) * 24 * time.Hour
	if duration == 0 {
		return 0, errors.New("invalid parsed duration")
	}
	return duration, nil
}
