package dto_astrologer

import (
	models "astrology-api/models/astrologermodel"
)

// LoggedInProfileResponse is what /astrologer/profile returns.
//
// The endpoint used to hand back the models.Astrologer row itself, which meant
// the response was whatever the struct happened to be: the denormalised
// primarySkill/allSkill/languageKnown columns came out as raw ids ("1"), the
// figures the profile screen shows (rating, followers, sessions) were not in it
// at all, and pincode and address — which live on the users row — could not be.
//
// The row is still embedded, so every key an existing client reads is still
// there. The fields below are added, and those that reuse one of the row's own
// JSON keys deliberately shadow it: for two fields with the same name at
// different depths, encoding/json takes the shallower one.
type LoggedInProfileResponse struct {
	*models.Astrologer

	// Master names in place of the stored ids. A legacy row holding free text
	// ("Hindi", "Astrology") is passed through as it stands.
	PrimarySkill  string `json:"PrimarySkill"`
	AllSkill      string `json:"AllSkill"`
	LanguageKnown string `json:"LanguageKnown"`

	// The public-facing name. Falls back to the first word of the legal name
	// for a row saved before astrologers.displayName existed.
	DisplayName string `json:"displayName"`

	// From the users row, which is where step 1 writes the address.
	Pincode string `json:"pincode"`
	Address string `json:"address"`

	// Figures for the profile header.
	TotalRating    int64   `json:"total_rating"`
	AverageRating  float64 `json:"average_rating"`
	TotalFollowers int64   `json:"total_followers"`
	TotalSession   int64   `json:"total_session"`

	// Which steps are done. Shadows the embedded row's ProfileCompletion
	// slice, which is empty until the profile is submitted.
	ProfileCompletion ProfileCompletionResponse `json:"ProfileCompletion"`

	// The astrologer's most recent status changes, newest first.
	StatusLogs []StatusLogEntry `json:"status_logs"`

	// The social links under snake_case keys, resolved from
	// astrologer_social_links and falling back to the astrologers columns.
	InstagramLink string `json:"instagram_link"`
	FacebookLink  string `json:"facebook_link"`
	YoutubeLink   string `json:"youtube_link"`
	TelegramLink  string `json:"telegram_link"`
	LinkedinLink  string `json:"linkedin_link"`
	WebsiteLink   string `json:"website_link"`
}

// ProfileCompletionResponse reports which of the ten steps have data.
//
// astrologer_profile_completion is only written when the profile is submitted,
// so an in-progress astrologer had an empty block. These flags are read from
// that row when it exists and otherwise computed from the data itself, which
// is what the screen needs either way.
type ProfileCompletionResponse struct {
	BasicProfile bool `json:"basic_profile"`
	Languages    bool `json:"languages"`
	ProfileImage bool `json:"profile_image"`
	Skills       bool `json:"skills"`
	Education    bool `json:"education"`
	Professional bool `json:"professional"`
	Experience   bool `json:"experience"`
	Bank         bool `json:"bank"`
	Documents    bool `json:"documents"`
	SocialLinks  bool `json:"social_links"`
	Availability bool `json:"availability"`

	CompletionPercentage int `json:"completion_percentage"`
}

// StatusLogEntry is one row of astrologer_status_logs.
type StatusLogEntry struct {
	ID              uint   `json:"id"`
	StatusType      string `json:"status_type"`
	PreviousStatus  string `json:"previous_status"`
	CurrentStatus   string `json:"current_status"`
	Remarks         string `json:"remarks"`
	StartedAt       string `json:"started_at"`
	EndedAt         string `json:"ended_at"`
	DurationSeconds int    `json:"duration_seconds"`
}

// SocialLinks is the set of links, from whichever source had them.
type SocialLinks struct {
	Instagram string
	Facebook  string
	Youtube   string
	Telegram  string
	Linkedin  string
	Website   string
}

// ProfileMeta carries everything the profile response needs that the
// astrologers row cannot supply on its own.
type ProfileMeta struct {
	PrimarySkillName string
	AllSkillNames    string
	LanguageNames    string

	DisplayName string
	Pincode     string
	Address     string

	TotalRating    int64
	AverageRating  float64
	TotalFollowers int64
	TotalSession   int64

	Completion ProfileCompletionResponse
	StatusLogs []StatusLogEntry
	Social     SocialLinks
}
