package controlplane

import "encoding/json"

// RelatedListRule is a neutral projection of a related-list defaulting rule.
// JSON tags mirror the engine payload shape for the fields kept here.
type RelatedListRule struct {
	Key              string   `json:"key,omitempty"`
	ParentObjectAPI  string   `json:"parentObjectApiName"`
	ChildObjectAPI   string   `json:"childObjectApiName"`
	LookupField      string   `json:"lookupField"`
	Bucket           string   `json:"bucket,omitempty"`
	SortOrder        int      `json:"sortOrder,omitempty"`
	AppendIfMissing  bool     `json:"appendIfMissing,omitempty"`
	Label            string   `json:"label,omitempty"`
	SecondaryLabel   string   `json:"secondaryLabel,omitempty"`
	LookupFieldLabel string   `json:"lookupFieldLabel,omitempty"`
	Fields           []string `json:"fields,omitempty"`
}

// PageLayoutDeclaration is the slim projection a provider hands to the
// presentation sink for a page layout. Config carries the raw payload.
type PageLayoutDeclaration struct {
	ObjectAPIName string
	LayoutName    string
	IsDefault     bool
	Config        []byte
}

// LayoutAssignmentDeclaration routes a record type to a layout for an object.
type LayoutAssignmentDeclaration struct {
	ObjectAPIName string `json:"objectApiName"`
	RecordType    string `json:"recordType"`
}

// ReportTypeDeclaration is the neutral projection of a report type seed. The
// raw sub-objects are carried as json.RawMessage for W3 round-trip fidelity.
type ReportTypeDeclaration struct {
	FullName      string          `json:"fullName"`
	Label         string          `json:"label"`
	Description   string          `json:"description,omitempty"`
	BaseObject    string          `json:"baseObject"`
	Deployed      bool            `json:"deployed"`
	Autogenerated bool            `json:"autogenerated"`
	Sections      json.RawMessage `json:"sections,omitempty"`
	Categories    json.RawMessage `json:"categories,omitempty"`
	Join          json.RawMessage `json:"join,omitempty"`
	Metadata      json.RawMessage `json:"metadata,omitempty"`
}

// UIActionDeclaration is the expanded, per-object projection of a UI action.
// Config carries the raw action config payload.
type UIActionDeclaration struct {
	ObjectAPIName string
	Name          string
	Label         string
	Type          string
	Icon          string
	TargetObject  string
	Config        []byte
}

// SearchScopeOrderItem is one entry in a search scope order list.
type SearchScopeOrderItem struct {
	Name  string `json:"name"`
	Label string `json:"label,omitempty"`
}

// SearchAllDefaultFieldsDeclaration declares the SOSL ALL default search fields
// for one object.
type SearchAllDefaultFieldsDeclaration struct {
	ObjectAPIName string   `json:"objectApiName"`
	Fields        []string `json:"fields"`
}

// HrefRewriteField declares a parent/field pair whose record-read href is
// rewritten. Field names match the engine exactly so a host adapter maps 1:1.
type HrefRewriteField struct {
	ParentApiName string `json:"parentApiName"`
	FieldApiName  string `json:"fieldApiName"`
}
