package contact

import (
	"tm/pkg/mongo"

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

// ContactStatus represents the status of a contact message
type ContactStatus string

const (
	ContactStatusPending    ContactStatus = "pending"
	ContactStatusInProgress ContactStatus = "in_progress"
	ContactStatusResolved   ContactStatus = "resolved"
	ContactStatusClosed     ContactStatus = "closed"
)

// Contact represents a contact us message in the system
type Contact struct {
	mongo.Model `bson:",inline"`
	FullName    string        `bson:"full_name" json:"full_name" validate:"required"`
	Email       string        `bson:"email" json:"email" validate:"required,email"`
	Phone       string        `bson:"phone" json:"phone" validate:"required"`
	Message     string        `bson:"message" json:"message" validate:"required"`
	Status      ContactStatus `bson:"status" json:"status" validate:"required,oneof=pending in_progress resolved closed"`
	AdminNotes  *string       `bson:"admin_notes,omitempty" json:"admin_notes,omitempty"`
	ResolvedAt  *int64        `bson:"resolved_at,omitempty" json:"resolved_at,omitempty"`
	ResolvedBy  *string       `bson:"resolved_by,omitempty" json:"resolved_by,omitempty"`
}

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

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

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

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

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

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

// IsPending returns true if the contact is pending
func (c *Contact) IsPending() bool {
	return c.Status == ContactStatusPending
}

// IsResolved returns true if the contact is resolved
func (c *Contact) IsResolved() bool {
	return c.Status == ContactStatusResolved || c.Status == ContactStatusClosed
}

// CanBeUpdated returns true if the contact can be updated
func (c *Contact) CanBeUpdated() bool {
	return c.Status != ContactStatusClosed
}
