package request

import (
	"campaign-pool-be/app/database/entity"
	"campaign-pool-be/utils/paginator"
	"time"
)

type CampaignTypesQueryRequest struct {
	Name       *string               `json:"name"`
	Pagination *paginator.Pagination `json:"pagination"`
}

type CampaignTypesCreateRequest struct {
	Name        string  `json:"name" validate:"required"`
	Description *string `json:"description"`
	CreatedById *uint   `json:"createdById"`
}

func (req CampaignTypesCreateRequest) ToEntity() *entity.CampaignTypes {
	return &entity.CampaignTypes{
		Name:        req.Name,
		Description: req.Description,
		CreatedAt:   time.Now(),
		UpdatedAt:   time.Now(),
	}
}

type CampaignTypesUpdateRequest struct {
	Name        string  `json:"name" validate:"required"`
	Description *string `json:"description"`
}

func (req CampaignTypesUpdateRequest) ToEntity() *entity.CampaignTypes {
	return &entity.CampaignTypes{
		Name:      req.Name,
		Description: req.Description,
		UpdatedAt: time.Now(),
	}
}

type CampaignTypesQueryRequestContext struct {
	Name string `json:"name"`
}

func (req CampaignTypesQueryRequestContext) ToParamRequest() CampaignTypesQueryRequest {
	var request CampaignTypesQueryRequest

	if name := req.Name; name != "" {
		request.Name = &name
	}

	return request
}

