package templates

import (
	"encoding/json"
	"time"
)

// ReportTemplate represents a stored report layout template.
type ReportTemplate struct {
	ID           int64           `json:"id"`
	ReportCode   string          `json:"report_code"`
	Version      int             `json:"version"`
	Name         string          `json:"name"`
	Description  string          `json:"description"`
	TemplateData json.RawMessage `json:"template_data"`
	SampleData   json.RawMessage `json:"sample_data,omitempty"`
	Status       string          `json:"status"` // draft, review, active, archived
	IsDefault    bool            `json:"is_default"`
	CreatedBy    *int64          `json:"created_by,omitempty"`
	UpdatedBy    *int64          `json:"updated_by,omitempty"`
	CreatedAt    time.Time       `json:"created_at"`
	UpdatedAt    time.Time       `json:"updated_at"`
}

// CreateTemplateInput represents the payload to create a new template.
type CreateTemplateInput struct {
	ReportCode   string          `json:"report_code"`
	Name         string          `json:"name"`
	Description  string          `json:"description"`
	TemplateData json.RawMessage `json:"template_data"`
	SampleData   json.RawMessage `json:"sample_data,omitempty"`
	Status       string          `json:"status"` // default 'draft'
}

// UpdateTemplateInput represents updates to an existing template.
type UpdateTemplateInput struct {
	Name         *string          `json:"name,omitempty"`
	Description  *string          `json:"description,omitempty"`
	TemplateData *json.RawMessage `json:"template_data,omitempty"`
	SampleData   *json.RawMessage `json:"sample_data,omitempty"`
	Status       *string          `json:"status,omitempty"`
}

// ReportParameter defines an input parameter expected by a report.
type ReportParameter struct {
	Name        string `json:"name"`
	Label       string `json:"label"`
	Type        string `json:"type"` // string, integer, date, boolean
	Required    bool   `json:"required"`
	Description string `json:"description,omitempty"`
}

// ReportDefinition represents a registered system report.
type ReportDefinition struct {
	Code        string            `json:"code"`
	Name        string            `json:"name"`
	Module      string            `json:"module"`
	Description string            `json:"description"`
	Parameters  []ReportParameter `json:"parameters"`
	SampleData  json.RawMessage   `json:"sample_data"`
}
