package domain import ( "encoding/json" "time" ) const ( AttachmentUploading = "uploading" // внутреннее намерение до 202, клиенту не видно AttachmentQueued = "queued" AttachmentProcessing = "processing" AttachmentReady = "ready" AttachmentFailed = "failed" AttachmentMissing = "missing" // карантин reconciler ) // Variant — результат обработки одной версии pipeline. type Variant struct { Name string `json:"name"` ContentType string `json:"content_type"` SizeBytes int64 `json:"size_bytes"` Width int `json:"width"` Height int `json:"height"` SHA256 string `json:"sha256"` ObjectKey string `json:"-"` PipelineVersion int `json:"-"` } // Attachment — метаданные вложения. Ключи S3 никогда не уходят клиенту. type Attachment struct { ID string ChatID string OwnerID string Filename string ObjectKey string // текущее место оригинала: staging до ready, конечный prefix после StagingKey string // staging-объект, пока он не удалён после публикации Status string ContentType string SizeBytes int64 SHA256 string ErrorCode string PipelineVersion int // версия, чей результат опубликован (0 — ещё нет) Variants []Variant CreatedAt time.Time UpdatedAt time.Time } // MarshalJSON — представление по контракту: queued/processing/ready/failed, // варианты текущей опубликованной версии, error_code только у failed. func (a Attachment) MarshalJSON() ([]byte, error) { variants := a.Variants if variants == nil { variants = []Variant{} } var errCode *string if a.Status == AttachmentFailed && a.ErrorCode != "" { ec := a.ErrorCode errCode = &ec } return json.Marshal(struct { ID string `json:"id"` ChatID string `json:"chat_id"` OwnerID string `json:"owner_id"` Filename string `json:"filename"` ContentType string `json:"content_type"` SizeBytes int64 `json:"size_bytes"` SHA256 string `json:"sha256"` Status string `json:"status"` Variants []Variant `json:"variants"` ErrorCode *string `json:"error_code"` CreatedAt string `json:"created_at"` UpdatedAt string `json:"updated_at"` }{ ID: a.ID, ChatID: a.ChatID, OwnerID: a.OwnerID, Filename: a.Filename, ContentType: a.ContentType, SizeBytes: a.SizeBytes, SHA256: a.SHA256, Status: a.Status, Variants: variants, ErrorCode: errCode, CreatedAt: a.CreatedAt.UTC().Truncate(time.Second).Format(time.RFC3339), UpdatedAt: a.UpdatedAt.UTC().Truncate(time.Second).Format(time.RFC3339), }) } // Job — сообщение broker по contracts/jobs.schema.json. Только ID и служебные // поля: ни байтов, ни URL, ни credentials. type Job struct { SchemaVersion int `json:"schema_version"` JobID string `json:"job_id"` Type string `json:"type"` AttachmentID string `json:"attachment_id"` PipelineVersion int `json:"pipeline_version"` Attempt int `json:"attempt"` CreatedAt string `json:"created_at"` Traceparent string `json:"traceparent,omitempty"` } const JobType = "attachment.process.v1"