package agencyopening

const (
	ActivityCode = "agency_opening"

	StatusDraft    = "draft"
	StatusActive   = "active"
	StatusDisabled = "disabled"
	StatusSettling = "settling"
	StatusSettled  = "settled"

	ApplicationStatusApplied  = "applied"
	ApplicationStatusApproved = "approved"
	ApplicationStatusPending  = "pending"
	ApplicationStatusGranted  = "granted"
	ApplicationStatusFailed   = "failed"
	ApplicationStatusExpired  = "expired"

	EventStatusConsumed  = "consumed"
	EventStatusDuplicate = "duplicate"
	EventStatusSkipped   = "skipped"

	GrantSourceAgencyOpening = "agency_opening"
)

// Reward 是代理开业贡献档位；RankNo 只保留为档位展示顺序和旧字段兼容，结算命中只看 ThresholdCoinSpent。
type Reward struct {
	AppCode            string
	CycleID            string
	RankNo             int32
	ThresholdCoinSpent int64
	RewardCoinAmount   int64
	CreatedAtMS        int64
	UpdatedAtMS        int64
}

// Cycle 是后台配置的 UTC 活动窗口；RegionID=0 表示全区域，正数周期优先覆盖对应区域。
type Cycle struct {
	AppCode          string
	RegionID         int64
	CycleID          string
	ActivityCode     string
	Title            string
	Status           string
	StartMS          int64
	EndMS            int64
	MinHostCount     int32
	MaxAgencyAgeDays int32
	CreatedByAdminID int64
	UpdatedByAdminID int64
	SettledAtMS      int64
	CreatedAtMS      int64
	UpdatedAtMS      int64
	Rewards          []Reward
}

// CycleCommand carries an admin mutation after transport normalization.
type CycleCommand struct {
	Cycle            Cycle
	OperatorAdminID  int64
	RequireNewRecord bool
}

// ListQuery filters admin list reads.
type ListQuery struct {
	RegionID int64
	Status   string
	StartMS  int64
	EndMS    int64
	Page     int32
	PageSize int32
}

// Application 同时保存申请和结算事实；RegionID 固化申请时代理的实际区域，即使周期是全区域也不写 0。
type Application struct {
	AppCode             string
	RegionID            int64
	ApplicationID       string
	CycleID             string
	AgencyID            int64
	AgencyOwnerUserID   int64
	AgencyName          string
	HostCount           int32
	AgencyCreatedAtMS   int64
	Status              string
	ScoreCoinAmount     int64
	RewardRankNo        int32
	RewardThresholdCoin int64
	RewardCoinAmount    int64
	WalletCommandID     string
	WalletTransactionID string
	FailureReason       string
	AppliedAtMS         int64
	ApprovedAtMS        int64
	ScoreStartMS        int64
	ScoreEndMS          int64
	ReviewedByAdminID   int64
	GrantedAtMS         int64
	CreatedAtMS         int64
	UpdatedAtMS         int64
}

// ApplicationQuery filters admin and H5 leaderboard reads.
type ApplicationQuery struct {
	RegionID          int64
	CycleID           string
	Status            string
	AgencyID          int64
	AgencyOwnerUserID int64
	Page              int32
	PageSize          int32
}

// AgencySnapshot is read from user-service at apply time so the activity record remains auditable.
type AgencySnapshot struct {
	AgencyID          int64
	RegionID          int64
	OwnerUserID       int64
	Name              string
	Status            string
	HostCount         int32
	AgencyCreatedAtMS int64
}

// Qualification combines the current cycle, agency snapshot and application state for H5.
type Qualification struct {
	Cycle            Cycle
	Application      Application
	Agency           AgencySnapshot
	Enabled          bool
	Eligible         bool
	Joined           bool
	IneligibleReason string
	ServerTimeMS     int64
}

// GiftEvent is the room-service gift fact projected into the applicant room owner's opening revenue.
// CoinSpent keeps the legacy field name but stores RoomGiftSent.gift_value/HeatValue.
type GiftEvent struct {
	EventID         string
	RegionID        int64
	RoomID          string
	RoomOwnerUserID int64
	TargetUserID    int64
	CoinSpent       int64
	OccurredAtMS    int64
}

// EventResult describes idempotent revenue consumption for one room event.
type EventResult struct {
	EventID string
	Status  string
}
