package request

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

type MagazineFilesGeneric interface {
	ToEntity()
}

type MagazineFilesQueryRequest struct {
	Title         string                `json:"title" validate:"required"`
	Description   string                `json:"description" validate:"required"`
	MagazineId    int                   `json:"magazine_id" validate:"required"`
	DownloadCount int                   `json:"download_count" 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 MagazineFilesCreateRequest struct {
	Title         string    `json:"title" validate:"required"`
	Description   string    `json:"description" validate:"required"`
	MagazineId    int       `json:"magazine_id" validate:"required"`
	DownloadCount int       `json:"download_count" 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 MagazineFilesCreateRequest) ToEntity() *entity.MagazineFiles {
	return &entity.MagazineFiles{
		Title:         req.Title,
		Description:   req.Description,
		MagazineId:    req.MagazineId,
		DownloadCount: req.DownloadCount,
		StatusId:      req.StatusId,
		IsPublish:     req.IsPublish,
		PublishedAt:   req.PublishedAt,
		IsActive:      req.IsActive,
	}
}

type MagazineFilesUpdateRequest struct {
	ID            uint      `json:"id" validate:"required"`
	Title         string    `json:"title" validate:"required"`
	Description   string    `json:"description" validate:"required"`
	MagazineId    int       `json:"magazine_id" validate:"required"`
	DownloadCount int       `json:"download_count" 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 MagazineFilesUpdateRequest) ToEntity() *entity.MagazineFiles {
	return &entity.MagazineFiles{
		ID:            req.ID,
		Title:         req.Title,
		Description:   req.Description,
		MagazineId:    req.MagazineId,
		DownloadCount: req.DownloadCount,
		StatusId:      req.StatusId,
		IsPublish:     req.IsPublish,
		PublishedAt:   req.PublishedAt,
		IsActive:      req.IsActive,
		CreatedAt:     req.CreatedAt,
		UpdatedAt:     req.UpdatedAt,
	}
}
