package wallet import "errors" var ( ErrDependencyUnavailable = errors.New("dependency unavailable") ErrInvalidAmount = errors.New("invalid amount") ErrInsufficientBalance = errors.New("insufficient balance") ) type Service struct { repo *Repository } func NewService(repo *Repository) *Service { return &Service{repo: repo} } func (s *Service) Account(userID uint64) (*AccountDTO, error) { if s.repo == nil { return nil, ErrDependencyUnavailable } return s.repo.Account(userID) } func (s *Service) Ledger(userID uint64) ([]LedgerDTO, error) { if s.repo == nil { return nil, ErrDependencyUnavailable } return s.repo.Ledger(userID) } func (s *Service) Recharge(userID uint64, req RechargeRequest) (*AccountDTO, error) { if s.repo == nil { return nil, ErrDependencyUnavailable } if req.Amount <= 0 { return nil, ErrInvalidAmount } return s.repo.Recharge(userID, req.Amount) } func (s *Service) AdminLedger(query AdminLedgerQuery) ([]AdminLedgerDTO, error) { if s.repo == nil { return nil, ErrDependencyUnavailable } return s.repo.AdminLedger(query) }