package tenant

import (
	"time"

	"codeberg.org/mapleopentech/monorepo/cloud/maplepress-backend/pkg/validation"
)

// CreateRequest represents the HTTP request for creating a tenant
type CreateRequest struct {
	Name string `json:"name"`
	Slug string `json:"slug"`
}

// Validate validates the create tenant request
// CWE-20: Improper Input Validation
func (r *CreateRequest) Validate() error {
	validator := validation.NewValidator()

	// Validate name: 3-100 chars, printable, no HTML
	if err := validator.ValidateRequired(r.Name, "name"); err != nil {
		return err
	}
	if err := validator.ValidateLength(r.Name, "name", 3, 100); err != nil {
		return err
	}
	if err := validator.ValidatePrintable(r.Name, "name"); err != nil {
		return err
	}
	if err := validator.ValidateNoHTML(r.Name, "name"); err != nil {
		return err
	}

	// Validate slug: uses existing slug validation (lowercase, hyphens, 3-63 chars)
	if err := validator.ValidateSlug(r.Slug, "slug"); err != nil {
		return err
	}

	// Sanitize inputs
	r.Name = validator.SanitizeString(r.Name)
	r.Slug = validator.SanitizeString(r.Slug)

	return nil
}

// CreateResponse represents the HTTP response after creating a tenant
type CreateResponse struct {
	ID        string    `json:"id"`
	Name      string    `json:"name"`
	Slug      string    `json:"slug"`
	Status    string    `json:"status"`
	CreatedAt time.Time `json:"created_at"`
}
