package jobqueue

import (
	"gorm.io/gorm"
	"time"
)

type JobLog struct {
	LogID         uint          `gorm:"primarykey;autoIncrement:true" json:"logId"`
	JobID         JobID         `json:"jobId" gorm:"type:varchar(255);foreignKey:JobID;references:ID"`
	ProcessID     int           `json:"processId"`
	StartTime     time.Time     `json:"startTime"`
	EndTime       time.Time     `json:"endTime"`
	ExitCode      int           `json:"exitCode"`
	Result        string        `json:"output" gorm:"type:TEXT"` // Assuming serialized JSON for any type
	ResourceUsage ResourceUsage `json:"resourceUsage" gorm:"embedded;embeddedPrefix:resource_usage_"`
	IO            IO            `json:"io" gorm:"embedded;embeddedPrefix:io_"`
	ErrorMsg      string        `json:"errorMsg"`
	IsSuccessful  bool          `json:"isSuccessful"`

	CreatedAt time.Time      `gorm:"column:created_at" json:"createdAt" yaml:"createdAt"`
	UpdatedAt time.Time      `gorm:"column:updated_at" json:"updatedAt" yaml:"updatedAt"`
	DeletedAt gorm.DeletedAt `gorm:"column:deleted_at;index" json:"-" yaml:"-"`
}

type ResourceUsage struct {
	Memory uint64  `json:"memory"`
	CPU    float64 `json:"cpu"`
}

type IO struct {
	Disk    int64 `json:"disk"`
	Network int64 `json:"network"`
}

func (JobLog) TableName() string {
	return globalTableNamePrefix + "job_logs"
}