package model

import (
	"strings"

	"github.com/tech/sendico/pkg/merrors"
)

// DemoRequest represents a request submitted from the marketing site to request a demo.
type DemoRequest struct {
	Name             string `json:"name"`
	OrganizationName string `json:"organizationName"`
	Phone            string `json:"phone"`
	WorkEmail        string `json:"workEmail"`
	PayoutVolume     string `json:"payoutVolume"`
	Comment          string `json:"comment,omitempty"`
}

// Normalize trims whitespace from all string fields.
func (dr *DemoRequest) Normalize() {
	if dr == nil {
		return
	}
	dr.Name = strings.TrimSpace(dr.Name)
	dr.OrganizationName = strings.TrimSpace(dr.OrganizationName)
	dr.Phone = strings.TrimSpace(dr.Phone)
	dr.WorkEmail = strings.TrimSpace(dr.WorkEmail)
	dr.PayoutVolume = strings.TrimSpace(dr.PayoutVolume)
	dr.Comment = strings.TrimSpace(dr.Comment)
}

// Validate ensures that all required fields are present.
func (dr *DemoRequest) Validate() error {
	if dr == nil {
		return merrors.InvalidArgument("request payload is empty")
	}
	if dr.Name == "" {
		return merrors.InvalidArgument("name must not be empty")
	}
	if dr.OrganizationName == "" {
		return merrors.InvalidArgument("organization name must not be empty")
	}
	if dr.Phone == "" {
		return merrors.InvalidArgument("phone must not be empty")
	}
	if dr.WorkEmail == "" {
		return merrors.InvalidArgument("work email must not be empty")
	}
	if dr.PayoutVolume == "" {
		return merrors.InvalidArgument("payout volume must not be empty")
	}
	return nil
}
