package request

import (
	"time"
	"web-qudo-be/app/database/entity"
	"web-qudo-be/utils/paginator"
)

type SubscriptionGeneric interface {
	ToEntity()
}

type SubscriptionQueryRequest struct {
	Email      *string               `json:"email"`
	Pagination *paginator.Pagination `json:"pagination"`
}

type SubscriptionCreateRequest struct {
	Email string `json:"email" validate:"required,email"`
}

func (req SubscriptionCreateRequest) ToEntity() *entity.Subscription {
	return &entity.Subscription{
		Email: req.Email,
	}
}

type SubscriptionUpdateRequest struct {
	ID    uint   `json:"id" validate:"required"`
	Email string `json:"email" validate:"required,email"`
}

func (req SubscriptionUpdateRequest) ToEntity() *entity.Subscription {
	return &entity.Subscription{
		ID:        req.ID,
		Email:     req.Email,
		UpdatedAt: time.Now(),
	}
}

type SubscriptionQueryRequestContext struct {
	Email string `json:"email"`
}

func (req SubscriptionQueryRequestContext) ToParamRequest() SubscriptionQueryRequest {
	var request SubscriptionQueryRequest

	if email := req.Email; email != "" {
		request.Email = &email
	}

	return request
}
