package request

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

type MagazinesGeneric interface {
	ToEntity()
}

type MagazinesQueryRequest struct {
	Title         string                `json:"title" validate:"required"`
	Description   string                `json:"description" validate:"required"`
	ThumbnailPath string                `json:"thumbnail_path" validate:"required"`
	ThumbnailUrl  string                `json:"thumbnail_url" validate:"required"`
	PageUrl       string                `json:"page_url" validate:"required"`
	CreatedById   int                   `json:"created_by_id" validate:"required"`
	StatusId      int                   `json:"status_id" validate:"required"`
	IsPublish     bool                  `json:"is_publish" validate:"required"`
	PublishedAt   time.Time             `json:"published_at" validate:"required"`
	IsActive      bool                  `json:"is_active" validate:"required"`
	Pagination    *paginator.Pagination `json:"pagination"`
}

type MagazinesCreateRequest struct {
	Title         string    `json:"title" validate:"required"`
	Description   string    `json:"description" validate:"required"`
	ThumbnailPath string    `json:"thumbnail_path" validate:"required"`
	ThumbnailUrl  string    `json:"thumbnail_url" validate:"required"`
	PageUrl       string    `json:"page_url" validate:"required"`
	CreatedById   int       `json:"created_by_id" validate:"required"`
	StatusId      int       `json:"status_id" validate:"required"`
	IsPublish     bool      `json:"is_publish" validate:"required"`
	PublishedAt   time.Time `json:"published_at" validate:"required"`
	IsActive      bool      `json:"is_active" validate:"required"`
}

func (req MagazinesCreateRequest) ToEntity() *entity.Magazines {
	return &entity.Magazines{
		Title:         req.Title,
		Description:   req.Description,
		ThumbnailPath: req.ThumbnailPath,
		ThumbnailUrl:  req.ThumbnailUrl,
		PageUrl:       req.PageUrl,
		CreatedById:   req.CreatedById,
		StatusId:      req.StatusId,
		IsPublish:     req.IsPublish,
		PublishedAt:   req.PublishedAt,
		IsActive:      req.IsActive,
	}
}

type MagazinesUpdateRequest struct {
	ID            uint      `json:"id" validate:"required"`
	Title         string    `json:"title" validate:"required"`
	Description   string    `json:"description" validate:"required"`
	ThumbnailPath string    `json:"thumbnail_path" validate:"required"`
	ThumbnailUrl  string    `json:"thumbnail_url" validate:"required"`
	PageUrl       string    `json:"page_url" validate:"required"`
	CreatedById   int       `json:"created_by_id" validate:"required"`
	StatusId      int       `json:"status_id" validate:"required"`
	IsPublish     bool      `json:"is_publish" validate:"required"`
	PublishedAt   time.Time `json:"published_at" validate:"required"`
	IsActive      bool      `json:"is_active" validate:"required"`
	CreatedAt     time.Time `json:"created_at"`
	UpdatedAt     time.Time `json:"updated_at"`
}

func (req MagazinesUpdateRequest) ToEntity() *entity.Magazines {
	return &entity.Magazines{
		ID:            req.ID,
		Title:         req.Title,
		Description:   req.Description,
		ThumbnailPath: req.ThumbnailPath,
		ThumbnailUrl:  req.ThumbnailUrl,
		PageUrl:       req.PageUrl,
		CreatedById:   req.CreatedById,
		StatusId:      req.StatusId,
		IsPublish:     req.IsPublish,
		PublishedAt:   req.PublishedAt,
		IsActive:      req.IsActive,
		CreatedAt:     req.CreatedAt,
		UpdatedAt:     req.UpdatedAt,
	}
}
