package activity

import "system-altrak/internal/domain"

type ActivityService interface {
	List(branchID uint, role string) ([]domain.ActivityLog, error)
	Dashboard(branchID uint, role string) (*DashboardResponse, error)
	Restore(resource string, id uint, branchID uint, role string) error
	Log(userID uint, username, role, module, action, details, ip, userAgent string, branchID uint) error
}

type serviceImpl struct {
	repo ActivityRepository
}

func NewService(repo ActivityRepository) ActivityService {
	return &serviceImpl{repo: repo}
}

func (s *serviceImpl) List(branchID uint, role string) ([]domain.ActivityLog, error) {
	return s.repo.List(branchID, role)
}

func (s *serviceImpl) Dashboard(branchID uint, role string) (*DashboardResponse, error) {
	return s.repo.Dashboard(branchID, role)
}

func (s *serviceImpl) Restore(resource string, id uint, branchID uint, role string) error {
	return s.repo.Restore(resource, id, branchID, role)
}

func (s *serviceImpl) Log(userID uint, username, role, module, action, details, ip, userAgent string, branchID uint) error {
	return s.repo.Log(&domain.ActivityLog{
		UserID:    userID,
		Username:  username,
		Role:      role,
		Module:    module,
		Action:    action,
		Details:   details,
		IPAddress: ip,
		UserAgent: userAgent,
		BranchID:  branchID,
	})
}
