package feedback

import (
	"tm/pkg/mongo"

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

// FeedbackType represents the type of feedback
type FeedbackType string

const (
	FeedbackTypeLike    FeedbackType = "like"
	FeedbackTypeDislike FeedbackType = "dislike"
)

// Feedback represents feedback given to a tender by a user
type Feedback struct {
	mongo.Model  `bson:",inline"`
	TenderID     string       `bson:"tender_id" json:"tender_id" validate:"required"`
	CustomerID   *string      `bson:"customer_id,omitempty" json:"customer_id,omitempty"`
	CompanyID    *string      `bson:"company_id,omitempty" json:"company_id,omitempty"`
	FeedbackType FeedbackType `bson:"feedback_type" json:"feedback_type" validate:"required,oneof=like dislike"`
}

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

// GetID returns the feedback ID (implements IDGetter interface)
func (f *Feedback) GetID() string {
	return f.ID.Hex()
}

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

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

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

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

// IsLike returns true if the feedback is a like
func (f *Feedback) IsLike() bool {
	return f.FeedbackType == FeedbackTypeLike
}

// IsDislike returns true if the feedback is a dislike
func (f *Feedback) IsDislike() bool {
	return f.FeedbackType == FeedbackTypeDislike
}
