package company_category

import "tm/pkg/response"

// CategoryForm represents the form for creating/updating a category
type CategoryForm struct {
	Name        string  `json:"name" valid:"required,length(2|100)" example:"Technology"`
	Description *string `json:"description,omitempty" valid:"optional,length(10|500)" example:"Technology related companies"`
	Thumbnail   *string `json:"thumbnail,omitempty" valid:"optional,url" example:"https://example.com/thumbnail.jpg"`
}

// SearchForm represents the form for searching categories with filters
type SearchForm struct {
	Search    *string `query:"q" valid:"optional"`
	Published *bool   `query:"published" valid:"optional"`
	Limit     *int    `query:"limit" valid:"optional,range(1|100)"`
	Offset    *int    `query:"offset" valid:"optional,range(0|1000000)"`
	SortBy    *string `query:"sort_by" valid:"optional,in(name|description|published|created_at|updated_at|published_at)"`
	SortOrder *string `query:"sort_order" valid:"optional,in(asc|desc)"`
}

// CategoryListResponse represents the response for listing categories
type CategoryListResponse struct {
	Categories []*CategoryResponse `json:"categories"`
	Meta       *response.Meta      `json:"-"`
}

// CategoryResponse represents the category data sent in API responses
type CategoryResponse struct {
	ID          string  `json:"id"`
	Name        string  `json:"name"`
	Description *string `json:"description,omitempty"`
	Thumbnail   *string `json:"thumbnail,omitempty"`
	Published   bool    `json:"published"`
	PublishedAt *int64  `json:"published_at,omitempty"`
	CreatedAt   int64   `json:"created_at"`
	UpdatedAt   int64   `json:"updated_at"`
}

// ToResponse converts Category to CategoryResponse
func (c *Category) ToResponse() *CategoryResponse {
	return &CategoryResponse{
		ID:          c.ID.Hex(),
		Name:        c.Name,
		Description: c.Description,
		Thumbnail:   c.Thumbnail,
		Published:   c.Published,
		PublishedAt: c.PublishedAt,
		CreatedAt:   c.CreatedAt,
		UpdatedAt:   c.UpdatedAt,
	}
}
