package dto

import "encoding/json"

// TarotInterpretation is the reading in one shape, whichever endpoint produced
// it.
//
// This exists because the vendor's coverage is uneven: tarot/daily carries the
// four life-area texts for the major arcana and nothing but the card's identity
// for the minor, while tarot/yes-no carries a meaning and a description for
// every card. A one-card reading on the Ten of Cups would otherwise come back
// with no words in it. The service falls back, and this is the shape both
// sources are mapped onto so a client renders one thing.
//
// The untouched vendor body is still returned alongside, in Reading.
type TarotInterpretation struct {
	// Meaning is the short verdict — "Yes", "No" — where the source has one.
	Meaning string `json:"meaning,omitempty"`

	Description string `json:"description,omitempty"`

	Health string `json:"health,omitempty"`

	Relationship string `json:"relationship,omitempty"`

	Career string `json:"career,omitempty"`

	Finance string `json:"finance,omitempty"`
}

// TarotDrawnCard is one card as it appears in a spread: which card, which way
// up, where it sits in the spread, and the artwork for that direction already
// resolved so the client does not have to choose between the upright and
// reversed sets itself.
type TarotDrawnCard struct {
	// Position names the card's role in the spread — past, present, future,
	// self, lover1, cause, advice. Empty for a single-card reading.
	Position string `json:"position,omitempty"`

	ID string `json:"id"`

	Name string `json:"name"`

	Arcana string `json:"arcana"`

	Suit string `json:"suit,omitempty"`

	Direction string `json:"direction"`

	// Image is the artwork for this direction, keyed by style.
	Image map[string]string `json:"image"`

	Back map[string]string `json:"back"`

	// Reading is this card's own interpretation as the vendor returned it,
	// present where the spread reads each card separately — the three-card
	// spread does, the love triangle does not, because upstream interprets that
	// one as a whole.
	Reading json.RawMessage `json:"reading,omitempty"`

	// Interpretation is the same content in a fixed shape, whichever endpoint
	// supplied it.
	Interpretation *TarotInterpretation `json:"interpretation,omitempty"`

	// ReadingSource names that endpoint: "daily" or "yes_no". Worth reading,
	// because the two bodies in Reading do not have the same fields.
	ReadingSource string `json:"reading_source,omitempty"`
}

// TarotCardDetailResponse is a card's catalogue page.
type TarotCardDetailResponse struct {
	Card TarotCard `json:"card"`

	// Reading is the general interpretation of the card, fetched on request.
	// Absent when it was not asked for or could not be fetched — the card
	// itself never fails, so a missing reading must not empty the page.
	Reading json.RawMessage `json:"reading,omitempty"`

	Interpretation *TarotInterpretation `json:"interpretation,omitempty"`

	ReadingSource string `json:"reading_source,omitempty"`

	Errors map[string]string `json:"errors,omitempty"`
}

// TarotShuffleResponse is the spread laid face-down for the querent to pick
// from. The cards carry their dealt direction, so choosing card 4 means
// choosing that card the way it was dealt.
type TarotShuffleResponse struct {
	Count int `json:"count"`

	Lang string `json:"lang"`

	Cards []TarotDrawnCard `json:"cards"`
}

// TarotReadingResponse is any completed reading.
type TarotReadingResponse struct {
	// Type identifies the spread: one_card, three_card, love, love_triangle,
	// yes_no, career, breakup, fortune_cookie.
	Type string `json:"type"`

	// Style is the variant within a type, where there is one.
	Style string `json:"style,omitempty"`

	Name string `json:"name,omitempty"`

	Lang string `json:"lang"`

	Cards []TarotDrawnCard `json:"cards,omitempty"`

	// Reading is the interpretation of the spread as a whole, passed through
	// from VedicAstroAPI untouched. For the three-card spread it is absent and
	// each card carries its own.
	Reading json.RawMessage `json:"reading,omitempty"`

	// Errors names whatever could not be fetched, so a spread that is partly
	// readable still returns.
	Errors map[string]string `json:"errors,omitempty"`
}
