package customer

// CreateCustomerForm represents the form for creating a new customer
type CreateCustomerForm struct {
	Type string `json:"type" valid:"required,in(individual|company|government)"`

	// Company assignments
	CompanyIDs []string `json:"company_ids,omitempty" valid:"optional"`

	// Individual customer fields
	FirstName *string `json:"first_name,omitempty" valid:"optional,length(2|50)"`
	LastName  *string `json:"last_name,omitempty" valid:"optional,length(2|50)"`
	FullName  *string `json:"full_name,omitempty" valid:"optional,length(2|100)"`
	Username  string  `json:"username" valid:"required,alphanum,length(3|30)"`
	Email     string  `json:"email" valid:"required,email"`
	Password  string  `json:"password" valid:"required,length(8|128)"`
	Phone     *string `json:"phone,omitempty" valid:"optional,length(10|20)"`
	Mobile    *string `json:"mobile,omitempty" valid:"optional,length(10|20)"`

	// Company customer fields
	RegistrationNumber *string `json:"registration_number,omitempty" valid:"optional,length(5|50)"`
	TaxID              *string `json:"tax_id,omitempty" valid:"optional,length(5|50)"`
	Industry           *string `json:"industry,omitempty" valid:"optional,length(2|100)"`

	// Address information
	Address *AddressForm `json:"address,omitempty"`

	// Business information
	BusinessType  *string  `json:"business_type,omitempty" valid:"optional,length(2|100)"`
	EmployeeCount *int     `json:"employee_count,omitempty" valid:"optional,range(1|100000)"`
	AnnualRevenue *float64 `json:"annual_revenue,omitempty" valid:"optional,range(0|999999999999)"`
	FoundedYear   *int     `json:"founded_year,omitempty" valid:"optional,range(1800|2100)"`

	// Contact person (for company customers)
	ContactPerson *ContactPersonForm `json:"contact_person,omitempty"`

	// Preferences and settings
	Language *string `json:"language,omitempty" valid:"optional,in(en|ar|fr|es|de|zh|ja|ko)"`
	Currency *string `json:"currency,omitempty" valid:"optional,in(USD|EUR|GBP|JPY|CAD|AUD|CHF|CNY|INR|BRL)"`
	Timezone *string `json:"timezone,omitempty" valid:"optional,length(3|50)"`
}

// UpdateCustomerForm represents the form for updating a customer
type UpdateCustomerForm struct {
	Type *string `json:"type,omitempty" valid:"optional,in(individual|company|government)"`

	// Company assignments
	CompanyIDs []string `json:"company_ids,omitempty" valid:"optional"`

	// Individual customer fields
	FirstName *string `json:"first_name,omitempty" valid:"optional,length(2|50)"`
	LastName  *string `json:"last_name,omitempty" valid:"optional,length(2|50)"`
	FullName  *string `json:"full_name,omitempty" valid:"optional,length(2|100)"`
	Username  *string `json:"username,omitempty" valid:"optional,alphanum,length(3|30)"`
	Email     *string `json:"email,omitempty" valid:"optional,email"`
	Phone     *string `json:"phone,omitempty" valid:"optional,length(10|20)"`
	Mobile    *string `json:"mobile,omitempty" valid:"optional,length(10|20)"`

	// Company customer fields
	CompanyName        *string `json:"company_name,omitempty" valid:"optional,length(2|200)"`
	RegistrationNumber *string `json:"registration_number,omitempty" valid:"optional,length(5|50)"`
	TaxID              *string `json:"tax_id,omitempty" valid:"optional,length(5|50)"`
	Industry           *string `json:"industry,omitempty" valid:"optional,length(2|100)"`

	// Address information
	Address *AddressForm `json:"address,omitempty"`

	// Business information
	BusinessType  *string  `json:"business_type,omitempty" valid:"optional,length(2|100)"`
	EmployeeCount *int     `json:"employee_count,omitempty" valid:"optional,range(1|100000)"`
	AnnualRevenue *float64 `json:"annual_revenue,omitempty" valid:"optional,range(0|999999999999)"`
	FoundedYear   *int     `json:"founded_year,omitempty" valid:"optional,range(1800|2100)"`

	// Contact person (for company customers)
	ContactPerson *ContactPersonForm `json:"contact_person,omitempty"`

	// Preferences and settings
	Language *string `json:"language,omitempty" valid:"optional,in(en|ar|fr|es|de|zh|ja|ko)"`
	Currency *string `json:"currency,omitempty" valid:"optional,in(USD|EUR|GBP|JPY|CAD|AUD|CHF|CNY|INR|BRL)"`
	Timezone *string `json:"timezone,omitempty" valid:"optional,length(3|50)"`
}

// ListCustomersForm represents the form for listing customers with filters
type ListCustomersForm struct {
	Search      *string `query:"search" valid:"optional"`
	Type        *string `query:"type" valid:"optional,in(individual|company|government)"`
	Status      *string `query:"status" valid:"optional,in(active|inactive|suspended|pending)"`
	CompanyID   *string `query:"company_id" valid:"optional,uuid"`
	Industry    *string `query:"industry" valid:"optional"`
	IsVerified  *bool   `query:"is_verified" valid:"optional"`
	IsCompliant *bool   `query:"is_compliant" valid:"optional"`
	Language    *string `query:"language" valid:"optional"`
	Currency    *string `query:"currency" valid:"optional"`
	Limit       *int    `query:"limit" valid:"optional,range(1|100)"`
	Offset      *int    `query:"offset" valid:"optional,min(0)"`
	SortBy      *string `query:"sort_by" valid:"optional,in(email|company_name|created_at|updated_at|status)"`
	SortOrder   *string `query:"sort_order" valid:"optional,in(asc|desc)"`
}

// UpdateCustomerStatusForm represents the form for updating customer status
type UpdateCustomerStatusForm struct {
	Status string `json:"status" valid:"required,in(active|inactive|suspended|pending)"`
}

// UpdateCustomerVerificationForm represents the form for updating customer verification status
type UpdateCustomerVerificationForm struct {
	IsVerified      bool    `json:"is_verified"`
	IsCompliant     bool    `json:"is_compliant"`
	ComplianceNotes *string `json:"compliance_notes,omitempty" valid:"optional,length(0|1000)"`
}

// SuspendCustomerForm represents the form for suspending a customer
type SuspendCustomerForm struct {
	Reason string `json:"reason" valid:"required,length(10|500)"`
}

// AddressForm represents the form for customer address
type AddressForm struct {
	Street      string `json:"street" valid:"required,length(5|200)"`
	City        string `json:"city" valid:"required,length(2|100)"`
	State       string `json:"state" valid:"required,length(2|100)"`
	PostalCode  string `json:"postal_code" valid:"required,length(3|20)"`
	Country     string `json:"country" valid:"required,length(2|100)"`
	AddressType string `json:"address_type" valid:"required,in(billing|shipping|both)"`
	IsDefault   bool   `json:"is_default"`
}

// ContactPersonForm represents the form for contact person
type ContactPersonForm struct {
	FirstName string  `json:"first_name" valid:"required,length(2|50)"`
	LastName  string  `json:"last_name" valid:"required,length(2|50)"`
	FullName  string  `json:"full_name" valid:"required,length(2|100)"`
	Position  string  `json:"position" valid:"required,length(2|100)"`
	Email     string  `json:"email" valid:"required,email"`
	Phone     string  `json:"phone" valid:"required,length(10|20)"`
	Mobile    *string `json:"mobile,omitempty" valid:"optional,length(10|20)"`
	IsPrimary bool    `json:"is_primary"`
}

// CustomerListResponse represents the response for listing customers
type CustomerListResponse struct {
	Customers  []*CustomerResponse `json:"customers"`
	Total      int64               `json:"total"`
	Limit      int                 `json:"limit"`
	Offset     int                 `json:"offset"`
	TotalPages int                 `json:"total_pages"`
}

// Mobile-specific forms (simplified for mobile app)
type CreateCustomerMobileForm struct {
	Type      string  `json:"type" valid:"required,in(individual|company)"`
	FirstName *string `json:"first_name,omitempty" valid:"optional,length(2|50)"`
	LastName  *string `json:"last_name,omitempty" valid:"optional,length(2|50)"`
	FullName  *string `json:"full_name,omitempty" valid:"optional,length(2|100)"`
	Username  string  `json:"username" valid:"required,alphanum,length(3|30)"`
	Email     string  `json:"email" valid:"required,email"`
	Password  string  `json:"password" valid:"required,length(8|128)"`
	Phone     *string `json:"phone,omitempty" valid:"optional,length(10|20)"`
	Mobile    *string `json:"mobile,omitempty" valid:"optional,length(10|20)"`

	// Company assignments
	CompanyIDs []string `json:"company_ids,omitempty" valid:"optional"`
	Industry   *string  `json:"industry,omitempty" valid:"optional,length(2|100)"`
}

type UpdateCustomerMobileForm struct {
	FirstName *string `json:"first_name,omitempty" valid:"optional,length(2|50)"`
	LastName  *string `json:"last_name,omitempty" valid:"optional,length(2|50)"`
	FullName  *string `json:"full_name,omitempty" valid:"optional,length(2|100)"`
	Phone     *string `json:"phone,omitempty" valid:"optional,length(10|20)"`
	Mobile    *string `json:"mobile,omitempty" valid:"optional,length(10|20)"`

	// Company assignments
	CompanyIDs []string `json:"company_ids,omitempty" valid:"optional"`
	Industry   *string  `json:"industry,omitempty" valid:"optional,length(2|100)"`
}

// Customer Authentication DTOs
type LoginForm struct {
	Username string `json:"username" valid:"required" example:"nakhostin"`
	Password string `json:"password" valid:"required" example:"Nima.1998"`
}

type RefreshTokenForm struct {
	RefreshToken string `json:"refresh_token" valid:"required"`
}

type ChangePasswordForm struct {
	OldPassword string `json:"old_password" valid:"required"`
	NewPassword string `json:"new_password" valid:"required,length(8|128)"`
}

type UpdateProfileForm struct {
	FirstName   *string `json:"first_name,omitempty" valid:"optional,length(2|50)"`
	LastName    *string `json:"last_name,omitempty" valid:"optional,length(2|50)"`
	FullName    *string `json:"full_name,omitempty" valid:"optional,length(2|100)"`
	Username    *string `json:"username,omitempty" valid:"optional,alphanum,length(3|30)"`
	Phone       *string `json:"phone,omitempty" valid:"optional,length(10|20)"`
	Mobile      *string `json:"mobile,omitempty" valid:"optional,length(10|20)"`
	CompanyName *string `json:"company_name,omitempty" valid:"optional,length(2|200)"`
	Industry    *string `json:"industry,omitempty" valid:"optional,length(2|100)"`
	Language    *string `json:"language,omitempty" valid:"optional,in(en|ar|fr|es|de|zh|ja|ko)"`
	Currency    *string `json:"currency,omitempty" valid:"optional,in(USD|EUR|GBP|JPY|CAD|AUD|CHF|CNY|INR|BRL)"`
	Timezone    *string `json:"timezone,omitempty" valid:"optional,length(3|50)"`
}

// Customer Authentication Response DTOs
type AuthResponse struct {
	Customer     *CustomerResponse `json:"customer"`
	AccessToken  string            `json:"access_token"`
	RefreshToken string            `json:"refresh_token"`
	ExpiresAt    int64             `json:"expires_at"`
}

// Company assignment forms
type AssignCompaniesForm struct {
	CompanyIDs []string `json:"company_ids" valid:"required"`
}

type RemoveCompaniesForm struct {
	CompanyIDs []string `json:"company_ids" valid:"required"`
}
