package instance

import (
	"encoding/json"
	"time"
)

const (
	StateUnknown  = "unknown"
	StateFiring   = "firing"
	StateResolved = "resolved"

	ObservationFirstFiring  = "first_firing"
	ObservationRepeatFiring = "repeat_firing"
	ObservationResolved     = "resolved"
)

// Instance is one occurrence of an Alertmanager label set. The same
// fingerprint with a new starts_at is a new occurrence.
type Instance struct {
	ID                 int64           `db:"id" json:"id"`
	OccurrenceKey      string          `db:"occurrence_key" json:"occurrence_key"`
	Fingerprint        string          `db:"fingerprint" json:"fingerprint"`
	Alertname          string          `db:"alertname" json:"alertname"`
	Classification     string          `db:"classification" json:"classification"`
	State              string          `db:"state" json:"state"`
	Labels             json.RawMessage `db:"labels" json:"labels" swaggertype:"object"`
	Annotations        json.RawMessage `db:"annotations" json:"annotations" swaggertype:"object"`
	GeneratorURL       string          `db:"generator_url" json:"generator_url"`
	StartsAt           time.Time       `db:"starts_at" json:"starts_at"`
	EndsAt             *time.Time      `db:"ends_at" json:"ends_at,omitempty"`
	FirstObservedAt    *time.Time      `db:"first_observed_at" json:"first_observed_at,omitempty"`
	LastObservedAt     *time.Time      `db:"last_observed_at" json:"last_observed_at,omitempty"`
	ResolvedObservedAt *time.Time      `db:"resolved_observed_at" json:"resolved_observed_at,omitempty"`
	ObservationCount   int             `db:"observation_count" json:"observation_count"`
	HistoryIncomplete  bool            `db:"history_incomplete" json:"history_incomplete"`
	CreatedAt          time.Time       `db:"created_at" json:"created_at"`
	UpdatedAt          time.Time       `db:"updated_at" json:"updated_at"`
}

type Snapshot struct {
	Fingerprint    string
	Alertname      string
	Classification string
	Labels         map[string]string
	Annotations    map[string]string
	GeneratorURL   string
	StartsAt       time.Time
}
