package request

import (
	"jaecoo-be/app/database/entity"
	"jaecoo-be/utils/paginator"
)

type PromotionsQueryRequest struct {
	Title      *string               `json:"title"`
	Pagination *paginator.Pagination `json:"pagination"`
}

type PromotionsQueryRequestContext struct {
	Title string `json:"title"`
}

func (req PromotionsQueryRequestContext) ToParamRequest() PromotionsQueryRequest {
	var request PromotionsQueryRequest

	if title := req.Title; title != "" {
		request.Title = &title
	}

	return request
}

type PromotionsCreateRequest struct {
	Title         string  `json:"title" validate:"required"`
	Description   *string `json:"description"`
	ThumbnailPath *string `json:"thumbnail_path"`
}

func (req PromotionsCreateRequest) ToEntity() *entity.Promotions {
	return &entity.Promotions{
		Title:         req.Title,
		Description:   req.Description,
		ThumbnailPath: req.ThumbnailPath,
	}
}

type PromotionsUpdateRequest struct {
	Title         *string `json:"title"`
	Description   *string `json:"description"`
	ThumbnailPath *string `json:"thumbnail_path"`
	IsActive      *bool   `json:"is_active"`
}

func (req PromotionsUpdateRequest) ToEntity() *entity.Promotions {
	return &entity.Promotions{
		Title:         getStringValue(req.Title),
		Description:   req.Description,
		ThumbnailPath: req.ThumbnailPath,
		IsActive:      req.IsActive,
	}
}

func getStringValue(s *string) string {
	if s == nil {
		return ""
	}
	return *s
}
