package feedback

import "tm/pkg/response"

// ToggleFeedbackForm represents the form for toggling feedback (like/dislike)
type ToggleFeedbackForm struct {
	Tender string       `json:"tender_id" validate:"required"`
	Type   FeedbackType `json:"feedback_type" validate:"required,oneof=like dislike"`
}

// SearchForm represents search criteria for feedback
type SearchForm struct {
	Tender   *string       `json:"tender_id,omitempty" valid:"optional"`
	Customer *string       `json:"customer_id,omitempty" valid:"optional"`
	Company  *string       `json:"company_id,omitempty" valid:"optional"`
	Type     *FeedbackType `json:"feedback_type,omitempty" valid:"optional,in(like|dislike)"`
	DateFrom *int64        `json:"date_from,omitempty" valid:"optional"`
	DateTo   *int64        `json:"date_to,omitempty" valid:"optional"`
}

type (
	FeedbackResponse struct {
		ID           string           `json:"id"`
		FeedbackType FeedbackType     `json:"feedback_type"`
		UpdatedAt    int64            `json:"updated_at"`
		CreatedAt    int64            `json:"created_at"`
		TenderID     string           `json:"tender_id"`
		CustomerID   *string          `json:"customer_id"`
		CompanyId    *string          `json:"company_id"`
		Tender       *tenderResponse  `json:"tender"`
		Company      *companyResponse `json:"company"`
	}

	tenderResponse struct {
		ID                  string                `json:"id"`
		NoticePublicationID string                `json:"notice_publication_id"`
		PublicationDate     int64                 `json:"publication_date"`
		Title               string                `json:"title"`
		Description         string                `json:"description"`
		ProcurementTypeCode string                `json:"procurement_type_code"`
		ProcedureCode       string                `json:"procedure_code"`
		EstimatedValue      float64               `json:"estimated_value"`
		Currency            string                `json:"currency"`
		Duration            string                `json:"duration"`
		DurationUnit        string                `json:"duration_unit"`
		TenderDeadline      int64                 `json:"tender_deadline"`
		SubmissionDeadline  int64                 `json:"submission_deadline"`
		CountryCode         string                `json:"country_code"`
		BuyerOrganization   *organizationResponse `json:"buyer_organization"`
		Status              string                `json:"status"`
	}

	organizationResponse struct {
		Name string `json:"name"`
	}

	companyResponse struct {
		ID   string `json:"id"`
		Name string `json:"name"`
	}
)

type FeedbackListResponse struct {
	Feedback []*FeedbackResponse `json:"feedback"`
	Meta     *response.Meta      `json:"meta"`
}

func (f *Feedback) ToResponse(tender *tenderResponse, company *companyResponse) *FeedbackResponse {
	return &FeedbackResponse{
		ID:           f.ID.Hex(),
		FeedbackType: f.FeedbackType,
		TenderID:     f.TenderID,
		CustomerID:   f.CustomerID,
		CompanyId:    f.CompanyID,
		UpdatedAt:    f.UpdatedAt,
		CreatedAt:    f.CreatedAt,
		Tender:       tender,
		Company:      company,
	}
}

type StatsResponse struct {
	CompanyID     string           `json:"company_id"`
	Company       *companyResponse `json:"company"`
	TotalLikes    int64            `json:"total_likes"`
	TotalDislikes int64            `json:"total_dislikes"`
	TotalFeedback int64            `json:"total_feedback"`
	LastUpdated   int64            `json:"last_updated"`
}
