package store

import "time"

// Contact represents a person in the CRM
type Contact struct {
	ID            string    `json:"id"`
	WorkspaceSlug string    `json:"workspaceSlug"`
	FirstName     string    `json:"firstName"`
	LastName      string    `json:"lastName"`
	Email         string    `json:"email"`
	Phone         string    `json:"phone"`
	CompanyID     *string   `json:"companyId,omitempty"`
	CompanyName   string    `json:"companyName,omitempty"`
	Title         string    `json:"title"`
	Notes         string    `json:"notes"`
	AvatarURL     string    `json:"avatarUrl"`
	CreatedAt     time.Time `json:"createdAt"`
	UpdatedAt     time.Time `json:"updatedAt"`
}

// Company represents an organization in the CRM
type Company struct {
	ID            string    `json:"id"`
	WorkspaceSlug string    `json:"workspaceSlug"`
	Name          string    `json:"name"`
	Domain        string    `json:"domain"`
	Website       string    `json:"website"`
	Industry      string    `json:"industry"`
	Size          string    `json:"size"`
	Notes         string    `json:"notes"`
	LogoURL       string    `json:"logoUrl"`
	CreatedAt     time.Time `json:"createdAt"`
	UpdatedAt     time.Time `json:"updatedAt"`
}

// ContactTaskLink links a contact to a task
type ContactTaskLink struct {
	ID        string    `json:"id"`
	ContactID string    `json:"contactId"`
	TaskID    string    `json:"taskId"`
	CreatedAt time.Time `json:"createdAt"`
}

// ContactEventLink links a contact to an event
type ContactEventLink struct {
	ID        string    `json:"id"`
	ContactID string    `json:"contactId"`
	EventID   string    `json:"eventId"`
	CreatedAt time.Time `json:"createdAt"`
}

// InboxItem represents a quick capture item
type InboxItem struct {
	ID                 string     `json:"id"`
	WorkspaceSlug      string     `json:"workspaceSlug"`
	Content            string     `json:"content"`
	Source             string     `json:"source"`
	Processed          bool       `json:"processed"`
	ProcessedAt        *time.Time `json:"processedAt,omitempty"`
	ProcessedEntityType *string   `json:"processedEntityType,omitempty"`
	ProcessedEntityID   *string   `json:"processedEntityId,omitempty"`
	CreatedAt          time.Time  `json:"createdAt"`
}

// TimeEntry represents logged time
type TimeEntry struct {
	ID             string     `json:"id"`
	WorkspaceSlug  string     `json:"workspaceSlug"`
	TaskID         *string    `json:"taskId,omitempty"`
	Description    string     `json:"description"`
	StartedAt      time.Time  `json:"startedAt"`
	EndedAt        *time.Time `json:"endedAt,omitempty"`
	DurationSeconds int       `json:"durationSeconds"`
	CreatedAt      time.Time  `json:"createdAt"`
	UpdatedAt      time.Time  `json:"updatedAt"`
}

// SavedView represents a user's saved filter/view
type SavedView struct {
	ID            string    `json:"id"`
	WorkspaceSlug string    `json:"workspaceSlug"`
	Name          string    `json:"name"`
	EntityType    string    `json:"entityType"`
	FilterJSON    string    `json:"filterJson"`
	SortJSON      string    `json:"sortJson"`
	IsDefault     bool      `json:"isDefault"`
	CreatedAt     time.Time `json:"createdAt"`
	UpdatedAt     time.Time `json:"updatedAt"`
}

// CreateContactInput for creating contacts
type CreateContactInput struct {
	WorkspaceSlug string  `json:"workspaceSlug" binding:"required"`
	FirstName     string  `json:"firstName"`
	LastName      string  `json:"lastName"`
	Email         string  `json:"email"`
	Phone         string  `json:"phone"`
	CompanyID     *string `json:"companyId"`
	Title         string  `json:"title"`
	Notes         string  `json:"notes"`
}

// UpdateContactInput for updating contacts
type UpdateContactInput struct {
	FirstName *string `json:"firstName"`
	LastName  *string `json:"lastName"`
	Email     *string `json:"email"`
	Phone     *string `json:"phone"`
	CompanyID *string `json:"companyId"`
	Title     *string `json:"title"`
	Notes     *string `json:"notes"`
}

// CreateCompanyInput for creating companies
type CreateCompanyInput struct {
	WorkspaceSlug string `json:"workspaceSlug" binding:"required"`
	Name          string `json:"name" binding:"required"`
	Domain        string `json:"domain"`
	Website       string `json:"website"`
	Industry      string `json:"industry"`
	Size          string `json:"size"`
	Notes         string `json:"notes"`
}

// UpdateCompanyInput for updating companies
type UpdateCompanyInput struct {
	Name     *string `json:"name"`
	Domain   *string `json:"domain"`
	Website  *string `json:"website"`
	Industry *string `json:"industry"`
	Size     *string `json:"size"`
	Notes    *string `json:"notes"`
}

// CreateInboxItemInput for quick capture
type CreateInboxItemInput struct {
	WorkspaceSlug string `json:"workspaceSlug" binding:"required"`
	Content       string `json:"content" binding:"required"`
	Source        string `json:"source"`
}

// CreateTimeEntryInput for time tracking
type CreateTimeEntryInput struct {
	WorkspaceSlug string     `json:"workspaceSlug" binding:"required"`
	TaskID        *string    `json:"taskId"`
	Description   string     `json:"description"`
	StartedAt     time.Time  `json:"startedAt" binding:"required"`
	EndedAt       *time.Time `json:"endedAt"`
}

// UpdateTimeEntryInput for updating time entries
type UpdateTimeEntryInput struct {
	Description *string    `json:"description"`
	EndedAt     *time.Time `json:"endedAt"`
}

// CreateSavedViewInput for saved views
type CreateSavedViewInput struct {
	WorkspaceSlug string `json:"workspaceSlug" binding:"required"`
	Name          string `json:"name" binding:"required"`
	EntityType    string `json:"entityType" binding:"required"`
	FilterJSON    string `json:"filterJson"`
	SortJSON      string `json:"sortJson"`
	IsDefault     bool   `json:"isDefault"`
}