| 187 | } |
| 188 | |
| 189 | func (a *CreateAccount) ValidateCreateAccount() error { |
| 190 | return validation.ValidateStruct(a, |
| 191 | validation.Field(&a.LedgerId, validation.When(a.BalanceId == "", validation.Required.Error("Ledger ID is required when Balance ID is not provided"))), |
| 192 | validation.Field(&a.IdentityId, validation.When(a.BalanceId == "", validation.Required.Error("Identity ID is required when Balance ID is not provided"))), |
| 193 | validation.Field(&a.Currency, validation.When(a.BalanceId == "", validation.Required.Error("currency is required when Balance ID is not provided"))), |
| 194 | validation.Field(&a.LedgerId, validation.By(func(value interface{}) error { |
| 195 | if a.BalanceId != "" && a.LedgerId != "" { |
| 196 | return errors.New("either LedgerId or BalanceId must be provided, not both") |
| 197 | } |
| 198 | return nil |
| 199 | })), |
| 200 | validation.Field(&a.Currency, validation.By(func(value interface{}) error { |
| 201 | if a.BalanceId != "" && a.Currency != "" { |
| 202 | return errors.New("either Currency or BalanceId must be provided, not both") |
| 203 | } |
| 204 | return nil |
| 205 | })), |
| 206 | ) |
| 207 | } |
| 208 | |
| 209 | func (l *CreateLedger) ToLedger() model.Ledger { |
| 210 | return model.Ledger{Name: l.Name, MetaData: l.MetaData} |