package request

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

type BannersQueryRequest struct {
	Title      *string               `json:"title"`
	Position   *string               `json:"position"`
	Status     *string               `json:"status"`
	Pagination *paginator.Pagination `json:"pagination"`
}

type BannersQueryRequestContext struct {
	Title    string `json:"title"`
	Position string `json:"position"`
	Status   string `json:"status"`
}

func (req BannersQueryRequestContext) ToParamRequest() BannersQueryRequest {
	var request BannersQueryRequest

	if title := req.Title; title != "" {
		request.Title = &title
	}
	if position := req.Position; position != "" {
		request.Position = &position
	}
	if status := req.Status; status != "" {
		request.Status = &status
	}

	return request
}

type BannersCreateRequest struct {
	Title         string  `json:"title" validate:"required"`
	Description   *string `json:"description"`
	ThumbnailPath *string `json:"thumbnail_path"`
	Position      *string `json:"position"`
	Status        *string `json:"status"`
}

func (req BannersCreateRequest) ToEntity() *entity.Banners {
	return &entity.Banners{
		Title:         req.Title,
		Description:   req.Description,
		ThumbnailPath: req.ThumbnailPath,
		Position:      req.Position,
		Status:        req.Status,
	}
}

type BannersUpdateRequest struct {
	Title         *string `json:"title"`
	Description   *string `json:"description"`
	ThumbnailPath *string `json:"thumbnail_path"`
	Position      *string `json:"position"`
	Status        *string `json:"status"`
	IsActive      *bool   `json:"is_active"`
}

func (req BannersUpdateRequest) ToEntity() *entity.Banners {
	return &entity.Banners{
		Title:         getStringValue(req.Title),
		Description:   req.Description,
		ThumbnailPath: req.ThumbnailPath,
		Position:      req.Position,
		Status:        req.Status,
		IsActive:      req.IsActive,
	}
}

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

