package services

import (
	"context"
	"fmt"
	"veza-backend-api/internal/types"
	"veza-backend-api/internal/models"
)

// {{SERVICE_NAME}}Service provides business logic for {{DOMAIN}}
type {{SERVICE_NAME}}Service struct {
	repo   types.{{REPOSITORY_INTERFACE}}
	logger types.Logger
}

// New{{SERVICE_NAME}}Service creates a new {{SERVICE_NAME}}Service instance
func New{{SERVICE_NAME}}Service(
	repo types.{{REPOSITORY_INTERFACE}},
	logger types.Logger,
) *{{SERVICE_NAME}}Service {
	return &{{SERVICE_NAME}}Service{
		repo:   repo,
		logger: logger,
	}
}

// Create{{ENTITY}} creates a new {{ENTITY}}
func (s *{{SERVICE_NAME}}Service) Create{{ENTITY}}(
	ctx context.Context,
	req *Create{{ENTITY}}Request,
) (*models.{{ENTITY}}, error) {
	// Validation
	if err := s.validateCreateRequest(req); err != nil {
		return nil, err
	}

	// Business logic
	{{ENTITY_LOWER}} := &models.{{ENTITY}}{
		// TODO: Map request fields to model
	}

	// Persistence
	if err := s.repo.Create(ctx, {{ENTITY_LOWER}}); err != nil {
		return nil, fmt.Errorf("failed to create {{ENTITY_LOWER}}: %w", err)
	}

	s.logger.Info("{{ENTITY_LOWER}} created", "id", {{ENTITY_LOWER}}.ID)

	return {{ENTITY_LOWER}}, nil
}

// Get{{ENTITY}}ByID retrieves a {{ENTITY}} by ID
func (s *{{SERVICE_NAME}}Service) Get{{ENTITY}}ByID(
	ctx context.Context,
	id uuid.UUID,
) (*models.{{ENTITY}}, error) {
	{{ENTITY_LOWER}}, err := s.repo.FindByID(ctx, id)
	if err != nil {
		return nil, fmt.Errorf("failed to get {{ENTITY_LOWER}}: %w", err)
	}

	return {{ENTITY_LOWER}}, nil
}

// validateCreateRequest validates the create request
func (s *{{SERVICE_NAME}}Service) validateCreateRequest(req *Create{{ENTITY}}Request) error {
	// TODO: Add validation logic
	if req == nil {
		return types.ErrValidation("request is required")
	}
	
	// Example validation
	// if req.Field == "" {
	//     return types.ErrValidation("field is required")
	// }

	return nil
}

// Create{{ENTITY}}Request represents a request to create a {{ENTITY}}
type Create{{ENTITY}}Request struct {
	// TODO: Add request fields
}







