package dto

import "time"

type OperationRecordRequest struct {
	IP           string
	Method       string
	Path         string
	Status       int
	LatencyMS    int64
	Agent        string
	ErrorMessage string
	Body         string
	Response     string
	UserID       uint
	RequestID    string
	TraceID      string
	DeviceID     string
}

type DataAccessRecordRequest struct {
	EventType   string
	Operation   string
	UserID      uint
	AuthorityID uint
	RequestID   string
	Method      string
	Path        string
	Detail      string
}

type DataAccessListRequest struct {
	Page        int    `json:"page"`
	PageSize    int    `json:"pageSize"`
	EventType   string `json:"eventType"`
	TargetTable string `json:"targetTable"`
}

type OperationRecordSearchRequest struct {
	Page     int    `form:"page"`
	PageSize int    `form:"pageSize"`
	Path     string `form:"path"`
	Method   string `form:"method"`
	Status   int    `form:"status"`
}

type LoginLogSearchRequest struct {
	Page     int    `form:"page"`
	PageSize int    `form:"pageSize"`
	Username string `form:"username"`
	Status   bool   `form:"status"`
}

type AuditIDQuery struct {
	ID uint `form:"ID"`
}

type AuditIDsRequest struct {
	IDs []int `json:"ids"`
}

type ErrorRecordRequest struct {
	Form      string `json:"form"`
	Info      string `json:"info"`
	Level     string `json:"level"`
	RequestID string `json:"request_id"`
	TraceID   string `json:"trace_id"`
	Solution  string `json:"solution"`
	Status    string `json:"status"`
}

// ErrorRecordMutationRequest mirrors the public error-record model. Pointer
// fields preserve the distinction between an omitted value and an explicitly
// supplied empty string, which is required by the update contract.
type ErrorRecordMutationRequest struct {
	ID        uint      `json:"ID"`
	CreatedAt time.Time `json:"CreatedAt"`
	UpdatedAt time.Time `json:"UpdatedAt"`
	Form      *string   `json:"form" binding:"required"`
	Info      *string   `json:"info"`
	Level     string    `json:"level"`
	RequestID string    `json:"request_id"`
	TraceID   string    `json:"trace_id"`
	Solution  *string   `json:"solution"`
	Status    string    `json:"status"`
}

type OperationRecordResponse struct {
	ID           uint      `json:"ID"`
	CreatedAt    time.Time `json:"CreatedAt"`
	UpdatedAt    time.Time `json:"UpdatedAt"`
	DeletedAt    any       `json:"-"`
	IP           string    `json:"ip"`
	Method       string    `json:"method"`
	Path         string    `json:"path"`
	Status       int       `json:"status"`
	LatencyMS    int64     `json:"latency_ms"`
	Agent        string    `json:"agent"`
	ErrorMessage string    `json:"error_message"`
	Body         string    `json:"body"`
	Response     string    `json:"resp"`
	UserID       uint      `json:"user_id"`
	RequestID    string    `json:"request_id"`
	TraceID      string    `json:"trace_id"`
	DeviceID     string    `json:"device_id"`
	User         any       `json:"user"`
}

type LoginLogResponse struct {
	ID           uint      `json:"ID"`
	CreatedAt    time.Time `json:"CreatedAt"`
	UpdatedAt    time.Time `json:"UpdatedAt"`
	DeletedAt    any       `json:"-"`
	Username     string    `json:"username"`
	IP           string    `json:"ip"`
	Status       bool      `json:"status"`
	ErrorMessage string    `json:"errorMessage"`
	Agent        string    `json:"agent"`
	UserID       uint      `json:"userId"`
	User         any       `json:"user"`
}

type DataAccessLogResponse struct {
	ID          uint      `json:"ID"`
	CreatedAt   time.Time `json:"CreatedAt"`
	UpdatedAt   time.Time `json:"UpdatedAt"`
	DeletedAt   any       `json:"-"`
	EventType   string    `json:"eventType"`
	TargetTable string    `json:"targetTable"`
	Operation   string    `json:"operation"`
	UserID      uint      `json:"userId"`
	AuthorityID uint      `json:"authorityId"`
	Scope       int       `json:"scope"`
	RequestID   string    `json:"requestId"`
	Method      string    `json:"method"`
	Path        string    `json:"path"`
	Detail      string    `json:"detail"`
}

type ErrorRecordResponse struct {
	ID        uint      `json:"ID"`
	CreatedAt time.Time `json:"CreatedAt"`
	UpdatedAt time.Time `json:"UpdatedAt"`
	DeletedAt any       `json:"-"`
	Form      *string   `json:"form"`
	Info      *string   `json:"info"`
	Level     string    `json:"level"`
	RequestID string    `json:"request_id"`
	TraceID   string    `json:"trace_id"`
	Solution  *string   `json:"solution"`
	Status    string    `json:"status"`
}

type LogDateResponse struct {
	Date      string `json:"date"`
	FileCount int    `json:"fileCount"`
}

type LogDatesResponse struct {
	Month string             `json:"month"`
	Dates []*LogDateResponse `json:"dates"`
}

type LogFileResponse struct {
	Path       string    `json:"path"`
	Name       string    `json:"name"`
	Size       int64     `json:"size"`
	ModifiedAt time.Time `json:"modifiedAt"`
}

type LogFilesResponse struct {
	Date  string             `json:"date"`
	Files []*LogFileResponse `json:"files"`
}

type LogContentResponse struct {
	Date           string    `json:"date"`
	Path           string    `json:"path"`
	Content        string    `json:"content"`
	LineCount      int       `json:"lineCount"`
	NextCursor     int64     `json:"nextCursor"`
	HasMore        bool      `json:"hasMore"`
	LimitedByBytes bool      `json:"limitedByBytes"`
	Size           int64     `json:"size"`
	ModifiedAt     time.Time `json:"modifiedAt"`
}
