package logger

import "go.uber.org/zap"

const (
	FieldRequestID  = "request_id"
	FieldProviderID = "provider_id"
	FieldModelName  = "model_name"
	FieldMethod     = "method"
	FieldPath       = "path"
	FieldStatusCode = "status"
	FieldLatency    = "latency"
	FieldClientIP   = "client_ip"
	FieldQuery      = "query"
	FieldBodySize   = "body_size"
	FieldSQL        = "sql"
	FieldRows       = "rows_affected"
)

func RequestID(id string) zap.Field {
	return zap.String(FieldRequestID, id)
}

func ProviderID(id string) zap.Field {
	return zap.String(FieldProviderID, id)
}

func ModelName(name string) zap.Field {
	return zap.String(FieldModelName, name)
}

func Method(method string) zap.Field {
	return zap.String(FieldMethod, method)
}

func Path(path string) zap.Field {
	return zap.String(FieldPath, path)
}

func StatusCode(code int) zap.Field {
	return zap.Int(FieldStatusCode, code)
}

func Latency(latency interface{}) zap.Field {
	switch v := latency.(type) {
	case int64:
		return zap.Int64(FieldLatency, v)
	case int:
		return zap.Int(FieldLatency, v)
	default:
		return zap.Any(FieldLatency, latency)
	}
}

func ClientIP(ip string) zap.Field {
	return zap.String(FieldClientIP, ip)
}

func Query(query string) zap.Field {
	return zap.String(FieldQuery, query)
}

func BodySize(size int) zap.Field {
	return zap.Int(FieldBodySize, size)
}

func SQL(sql string) zap.Field {
	return zap.String(FieldSQL, sql)
}

func Rows(rows int64) zap.Field {
	return zap.Int64(FieldRows, rows)
}

func Err(err error) zap.Field {
	return zap.Error(err)
}
