package contact

import "tm/pkg/response"

// CreateContactForm represents the form for creating a new contact message
type CreateContactForm struct {
	FullName      string `json:"full_name" valid:"required,length(2|100)" example:"John Doe"`
	Email         string `json:"email" valid:"required,email" example:"john.doe@example.com"`
	Phone         string `json:"phone" valid:"required,length(10|20)" example:"+1234567890"`
	Message       string `json:"message" valid:"required,length(10|1000)" example:"I have a question about your services"`
	HCaptchaToken string `json:"hcaptcha_token" valid:"required" example:"P0_eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiJ9..."`
}

// UpdateContactStatusForm represents the form for updating contact status (admin only)
type UpdateContactStatusForm struct {
	Status     string  `json:"status" valid:"required,in(pending|in_progress|resolved|closed)" example:"in_progress"`
	AdminNotes *string `json:"admin_notes,omitempty" valid:"optional,length(0|500)" example:"Customer inquiry handled"`
}

// SearchContactsForm represents the form for searching contacts with filters
type SearchContactsForm struct {
	Search   *string `query:"q" valid:"optional"`
	Status   *string `query:"status" valid:"optional,in(pending|in_progress|resolved|closed)"`
	DateFrom *int64  `query:"date_from" valid:"optional"`
	DateTo   *int64  `query:"date_to" valid:"optional"`
}

// ContactResponse represents the contact data sent in API responses
type ContactResponse struct {
	ID         string  `json:"id"`
	FullName   string  `json:"full_name"`
	Email      string  `json:"email"`
	Phone      string  `json:"phone"`
	Message    string  `json:"message"`
	Status     string  `json:"status"`
	AdminNotes *string `json:"admin_notes,omitempty"`
	ResolvedAt *int64  `json:"resolved_at,omitempty"`
	ResolvedBy *string `json:"resolved_by,omitempty"`
	CreatedAt  int64   `json:"created_at"`
	UpdatedAt  int64   `json:"updated_at"`
}

// PublicContactResponse represents the contact data sent in public API responses (limited fields)
type PublicContactResponse struct {
	ID        string `json:"id"`
	Status    string `json:"status"`
	CreatedAt int64  `json:"created_at"`
}

// ToResponse converts Contact to ContactResponse
func (c *Contact) ToResponse() *ContactResponse {
	return &ContactResponse{
		ID:         c.ID.Hex(),
		FullName:   c.FullName,
		Email:      c.Email,
		Phone:      c.Phone,
		Message:    c.Message,
		Status:     string(c.Status),
		AdminNotes: c.AdminNotes,
		ResolvedAt: c.ResolvedAt,
		ResolvedBy: c.ResolvedBy,
		CreatedAt:  c.CreatedAt,
		UpdatedAt:  c.UpdatedAt,
	}
}

// ToPublicResponse converts Contact to PublicContactResponse (limited fields for public API)
func (c *Contact) ToPublicResponse() *PublicContactResponse {
	return &PublicContactResponse{
		ID:        c.ID.Hex(),
		Status:    string(c.Status),
		CreatedAt: c.CreatedAt,
	}
}

// ContactListResponse represents the response for listing contacts
type ContactListResponse struct {
	Contacts []*ContactResponse `json:"contacts"`
	Meta     *response.Meta     `json:"-"`
}
