package cms

import (
	"tm/pkg/mongo"

	"go.mongodb.org/mongo-driver/v2/bson"
)

// CMS represents the content management system for the landing page
type CMS struct {
	mongo.Model `bson:",inline"`
	Key         string         `bson:"key" json:"key"`
	Language    string         `bson:"language" json:"language"`
	CompanyName string         `bson:"company_name" json:"company_name"`
	Country     string         `bson:"country" json:"country"`
	Type        CMSType        `bson:"type" json:"type"`
	Hero        heroSection    `bson:"hero" json:"hero"`
	Chart       chartSection   `bson:"chart" json:"chart"`
	Features    cardSection    `bson:"features" json:"features"`
	Challenges  cardSection    `bson:"challenges" json:"challenges"`
	Advantages  cardSection    `bson:"advantages" json:"advantages"`
	Contact     contactSection `bson:"contact" json:"contact"`
	Footer      footerSection  `bson:"footer" json:"footer"`
}

type CMSType string

const (
	CMSTypeCompany      CMSType = "company"
	CMSTypeOrganization CMSType = "organization"
)

// SetID sets the CMS ID (implements IDSetter interface)
func (c *CMS) SetID(id string) {
	c.ID, _ = bson.ObjectIDFromHex(id)
}

// GetID returns the CMS ID (implements IDGetter interface)
func (c *CMS) GetID() string {
	return c.ID.Hex()
}

// SetCreatedAt sets the created timestamp (implements Timestamp interface)
func (c *CMS) SetCreatedAt(timestamp int64) {
	c.CreatedAt = timestamp
}

// SetUpdatedAt sets the updated timestamp (implements Timestamp interface)
func (c *CMS) SetUpdatedAt(timestamp int64) {
	c.UpdatedAt = timestamp
}

// GetCreatedAt returns the created timestamp (implements Timestamp interface)
func (c *CMS) GetCreatedAt() int64 {
	return c.CreatedAt
}

// GetUpdatedAt returns the updated timestamp (implements Timestamp interface)
func (c *CMS) GetUpdatedAt() int64 {
	return c.UpdatedAt
}

// heroSection represents the hero section of the landing page
type heroSection struct {
	Title       string `bson:"title" json:"title"`
	Description string `bson:"description" json:"description"`
	ButtonText  string `bson:"button_text" json:"button_text"`
	ButtonLink  string `bson:"button_link" json:"button_link"`
	GifFile     string `bson:"gif_file" json:"gif_file"`
}

// chartSection represents the chart section of the landing page
type chartSection struct {
	Title        string       `bson:"title" json:"title"`
	MissedAmount string       `bson:"missed_amount" json:"missed_amount"`
	Data         []chartPoint `bson:"data" json:"data"`
}

type chartPoint struct {
	Key   string `bson:"key" json:"key"`
	Value int    `bson:"value" json:"value"`
}

// cardSection represents the card section of the landing page
type cardSection struct {
	Title       string `bson:"title" json:"title"`
	Description string `bson:"description" json:"description"`
	Cards       []card `bson:"cards" json:"cards"`
}

// card represents a card in the card section
type card struct {
	ID          string `bson:"id" json:"id"`
	Icon        string `bson:"icon" json:"icon"`
	Title       string `bson:"title" json:"title"`
	Description string `bson:"description" json:"description"`
}

// contactSection represents the contact section of the landing page
type contactSection struct {
	Title            string      `bson:"title" json:"title"`
	Description      string      `bson:"description" json:"description"`
	SubmitButtonText string      `bson:"submit_button_text" json:"submit_button_text"`
	Fields           []formField `bson:"fields" json:"fields"`
}

// formField represents a form field in the contact section
type formField struct {
	ID          string `bson:"id" json:"id"`
	Name        string `bson:"name" json:"name"`
	Label       string `bson:"label" json:"label"`
	Placeholder string `bson:"placeholder" json:"placeholder"`
	Required    bool   `bson:"required" json:"required"`
}

// footerSection represents the footer section of the landing page
type footerSection struct {
	Email     string `bson:"email" json:"email"`
	Phone     string `bson:"phone" json:"phone"`
	Location  string `bson:"location" json:"location"`
	Tagline   string `bson:"tagline" json:"tagline"`
	Copyright string `bson:"copyright" json:"copyright"`
}
