package main

import "fmt"

type Actor struct {
	ID                string `json:"id"`
	Type              string `json:"type"`
	URL               string `json:"url"`
	Name              string `json:"name"`
	PreferredUsername string `json:"preferredUsername,omitempty"`
	Summary           string `json:"summary,omitempty"`

	PublicKey PublicKey `json:"publicKey,omitempty"`

	Inbox     string `json:"inbox,omitempty"`
	Outbox    string `json:"outbo,omitempty"`
	Followers string `json:"followers,omitempty"`
	Following string `json:"following,omitempty"`

	Icon  *Link `json:"icon,omitempty"`
	Image *Link `json:"image,omitempty"`

	Endpoints map[string]string `json:"endpoints,omitempty"`
}

type Link struct {
	Type      string `json:"type"`
	MediaType string `json:"mediaType"`
	URL       string `json:"url"`
}

type PublicKey struct {
	ID           string `json:"id"`
	Owner        string `json:"owner"`
	PublicKeyPem string `json:"publicKeyPem"`
}

type ProfileProvider struct {
	domain string
}

func NewProfileProvider(domain string) (*ProfileProvider, error) {
	return &ProfileProvider{
		domain: domain,
	}, nil
}

func (pp *ProfileProvider) Get(userID string) (*Actor, error) {
	userRoot := fmt.Sprintf("https://%s/users/%s", pp.domain, userID)
	return &Actor{
		ID:        userRoot,
		Type:      "Person",
		URL:       fmt.Sprintf("https://%s/@%s", pp.domain, userID),
		Name:      userID,
		Inbox:     userRoot + "/inbox",
		Outbox:    userRoot + "/outbox",
		Followers: userRoot + "/followers",
		Following: userRoot + "/following",
		Endpoints: map[string]string{
			"sharedInbox": fmt.Sprintf("https://%s/inbox", pp.domain),
		},
		PublicKey: PublicKey{
			ID:           userRoot + "#main-key",
			Owner:        userRoot,
			PublicKeyPem: "-----BEGIN PUBLIC KEY-----...-----END PUBLIC KEY-----",
		},
	}, nil
}
