package request

import (
	"go-humas-be/app/database/entity"
	"go-humas-be/utils/paginator"
	"time"
)

type PpidDataCategoriesGeneric interface {
	ToEntity()
}

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

type PpidDataCategoriesCreateRequest struct {
	Title         string  `json:"title" validate:"required"`
	Description   string  `json:"description" validate:"required"`
	Slug          string  `json:"slug" validate:"required"`
	ThumbnailPath *string `json:"thumbnailPath"`
}

func (req PpidDataCategoriesCreateRequest) ToEntity() *entity.PpidDataCategories {
	return &entity.PpidDataCategories{
		Title:         req.Title,
		Description:   req.Description,
		Slug:          req.Slug,
		ThumbnailPath: req.ThumbnailPath,
	}
}

type PpidDataCategoriesUpdateRequest struct {
	ID            uint    `json:"id" validate:"required"`
	Title         string  `json:"title" validate:"required"`
	Description   string  `json:"description" validate:"required"`
	Slug          string  `json:"slug" validate:"required"`
	ThumbnailPath *string `json:"thumbnailPath"`
}

func (req PpidDataCategoriesUpdateRequest) ToEntity() *entity.PpidDataCategories {
	return &entity.PpidDataCategories{
		ID:            req.ID,
		Title:         req.Title,
		Description:   req.Description,
		Slug:          req.Slug,
		ThumbnailPath: req.ThumbnailPath,
		UpdatedAt:     time.Now(),
	}
}

type PpidDataCategoriesQueryRequestContext struct {
	Title       string `json:"title"`
	Description string `json:"description"`
}

func (req PpidDataCategoriesQueryRequestContext) ToParamRequest() PpidDataCategoriesQueryRequest {
	var request PpidDataCategoriesQueryRequest

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

	return request
}
