package api

import "time"

// API request/response models
type ContentItem struct {
	ID               string    `json:"id"`
	SiteID           string    `json:"site_id"`
	HTMLContent      string    `json:"html_content"`
	OriginalTemplate string    `json:"original_template"`
	CreatedAt        time.Time `json:"created_at"`
	UpdatedAt        time.Time `json:"updated_at"`
	LastEditedBy     string    `json:"last_edited_by"`
}

type ContentVersion struct {
	VersionID        int64     `json:"version_id"`
	ContentID        string    `json:"content_id"`
	SiteID           string    `json:"site_id"`
	HTMLContent      string    `json:"html_content"`
	OriginalTemplate string    `json:"original_template"`
	CreatedAt        time.Time `json:"created_at"`
	CreatedBy        string    `json:"created_by"`
}

type ContentResponse struct {
	Content []ContentItem `json:"content"`
}

type ContentVersionsResponse struct {
	Versions []ContentVersion `json:"versions"`
}

// Element context for backend ID generation
type ElementContext struct {
	Tag             string   `json:"tag"`
	Classes         []string `json:"classes"`
	OriginalContent string   `json:"original_content"`
	ParentContext   string   `json:"parent_context"`
	Purpose         string   `json:"purpose"`
}

// Request models
type CreateContentRequest struct {
	HTMLMarkup       string `json:"html_markup"`          // HTML markup of the element
	FilePath         string `json:"file_path"`            // File path for consistent ID generation
	HTMLContent      string `json:"html_content"`         // HTML content value
	OriginalTemplate string `json:"original_template"`    // Original template markup
	SiteID           string `json:"site_id,omitempty"`    // Site identifier
	CreatedBy        string `json:"created_by,omitempty"` // User who created the content
}

type RollbackContentRequest struct {
	VersionID    int64  `json:"version_id"`
	RolledBackBy string `json:"rolled_back_by,omitempty"`
}

// Collection API models
type CollectionItem struct {
	ID            string               `json:"id"`
	SiteID        string               `json:"site_id"`
	ContainerHTML string               `json:"container_html"`
	CreatedAt     time.Time            `json:"created_at"`
	UpdatedAt     time.Time            `json:"updated_at"`
	LastEditedBy  string               `json:"last_edited_by"`
	Templates     []CollectionTemplate `json:"templates,omitempty"`
	Items         []CollectionItemData `json:"items,omitempty"`
}

type CollectionTemplate struct {
	TemplateID   int       `json:"template_id"`
	CollectionID string    `json:"collection_id"`
	SiteID       string    `json:"site_id"`
	Name         string    `json:"name"`
	HTMLTemplate string    `json:"html_template"`
	IsDefault    bool      `json:"is_default"`
	CreatedAt    time.Time `json:"created_at"`
}

type CollectionItemData struct {
	ItemID       string    `json:"item_id"`
	CollectionID string    `json:"collection_id"`
	SiteID       string    `json:"site_id"`
	TemplateID   int       `json:"template_id"`
	HTMLContent  string    `json:"html_content"`
	Position     int       `json:"position"`
	CreatedAt    time.Time `json:"created_at"`
	UpdatedAt    time.Time `json:"updated_at"`
	LastEditedBy string    `json:"last_edited_by"`
	TemplateName string    `json:"template_name,omitempty"`
}

type CollectionResponse struct {
	Collections []CollectionItem `json:"collections"`
}

// Collection request models
type CreateCollectionRequest struct {
	ContainerHTML string `json:"container_html"`
	SiteID        string `json:"site_id,omitempty"`
	CreatedBy     string `json:"created_by,omitempty"`
}

type CreateCollectionTemplateRequest struct {
	Name         string `json:"name"`
	HTMLTemplate string `json:"html_template"`
	IsDefault    bool   `json:"is_default"`
	CollectionID string `json:"collection_id,omitempty"`
	SiteID       string `json:"site_id,omitempty"`
}

type CreateCollectionItemRequest struct {
	TemplateID   int    `json:"template_id"`
	HTMLContent  string `json:"html_content"`
	Position     int    `json:"position"`
	CollectionID string `json:"collection_id,omitempty"`
	SiteID       string `json:"site_id,omitempty"`
	CreatedBy    string `json:"created_by,omitempty"`
}

type UpdateCollectionItemRequest struct {
	HTMLContent string `json:"html_content"`
	Position    int    `json:"position"`
	UpdatedBy   string `json:"updated_by,omitempty"`
}
