package realtime

// WebSocket event type names.
const (
	TypeMailCreated    = "mail.created"
	TypeMailUpdated    = "mail.updated"
	TypeMailDeleted    = "mail.deleted"
	TypeOutboxUpdated  = "outbox.updated"
	TypeContactUpdated = "contact.updated"
	TypeDriveFileChanged = "drive.file_changed"
	TypeDriveShareUpdated = "drive.share_updated"

	TypeWSPing = "ws.ping"
	TypeWSPong = "ws.pong"
)

// MailEventPayload is the payload for mail.created, mail.updated, and mail.deleted.
type MailEventPayload struct {
	MessageID string `json:"message_id"`
	AccountID string `json:"account_id"`
}

// OutboxEventPayload is the payload for outbox.updated.
type OutboxEventPayload struct {
	AccountID string `json:"account_id"`
}

// ContactEventPayload is the payload for contact.updated.
type ContactEventPayload struct {
	ContactID string `json:"contact_id"`
	AccountID string `json:"account_id,omitempty"`
}

func NewMailCreatedEvent(messageID, accountID string) Event {
	return Event{
		Type: TypeMailCreated,
		Payload: MailEventPayload{
			MessageID: messageID,
			AccountID: accountID,
		},
	}
}

func NewMailUpdatedEvent(messageID, accountID string) Event {
	return Event{
		Type: TypeMailUpdated,
		Payload: MailEventPayload{
			MessageID: messageID,
			AccountID: accountID,
		},
	}
}

func NewMailDeletedEvent(messageID, accountID string) Event {
	return Event{
		Type: TypeMailDeleted,
		Payload: MailEventPayload{
			MessageID: messageID,
			AccountID: accountID,
		},
	}
}

func NewOutboxUpdatedEvent(accountID string) Event {
	return Event{
		Type: TypeOutboxUpdated,
		Payload: OutboxEventPayload{
			AccountID: accountID,
		},
	}
}

func NewContactUpdatedEvent(contactID, accountID string) Event {
	return Event{
		Type: TypeContactUpdated,
		Payload: ContactEventPayload{
			ContactID: contactID,
			AccountID: accountID,
		},
	}
}

// DriveEventPayload is the payload for drive.file_changed and drive.share_updated.
type DriveEventPayload struct {
	Path string `json:"path"`
}

func NewDriveFileChangedEvent(path string) Event {
	return Event{
		Type: TypeDriveFileChanged,
		Payload: DriveEventPayload{Path: path},
	}
}

func NewDriveShareUpdatedEvent(path string) Event {
	return Event{
		Type: TypeDriveShareUpdated,
		Payload: DriveEventPayload{Path: path},
	}
}
