package system

import (
	"context"
	"time"
)

type ExportCondition struct {
	ID                   uint
	CreatedAt, UpdatedAt time.Time
	TemplateID           string
	From, Column         string
	Operator             string
}
type ExportJoin struct {
	ID                   uint
	CreatedAt, UpdatedAt time.Time
	TemplateID           string
	Join, Table, On      string
}
type ExportTemplate struct {
	ID                                                                uint
	CreatedAt                                                         time.Time
	UpdatedAt                                                         time.Time
	DBName, Name, TableName, TemplateID, TemplateInfo, SQL, ImportSQL string
	Limit                                                             *int
	Order                                                             string
	Conditions                                                        []ExportCondition
	Joins                                                             []ExportJoin
	StartCreatedAt                                                    *time.Time
	EndCreatedAt                                                      *time.Time
}
type ExportRepo interface {
	CreateExportTemplate(context.Context, *ExportTemplate) error
	UpdateExportTemplate(context.Context, *ExportTemplate) error
	DeleteExportTemplates(context.Context, []uint) error
	FindExportTemplate(context.Context, uint, string) (*ExportTemplate, error)
	ListExportTemplates(context.Context, int, int, *ExportTemplate) ([]*ExportTemplate, int64, error)
	QueryExport(context.Context, *ExportTemplate, map[string]string) ([]map[string]any, string, error)
	PreviewExport(context.Context, *ExportTemplate, map[string]string) (string, error)
	ImportExportRows(context.Context, *ExportTemplate, []map[string]any) error
}
type ExportUsecase struct{ ExportRepo }

func NewExportUsecase(repo ExportRepo) *ExportUsecase { return &ExportUsecase{ExportRepo: repo} }
