package domain import ( "time" dbgen "github.com/SamuelTariku/FortuneBet-Backend/gen/db" "github.com/jackc/pgx/v5/pgtype" ) type Branch struct { ID int64 Name string Location string WalletID int64 BranchManagerID int64 CompanyID int64 IsActive bool IsSelfOwned bool ProfitPercentage float32 } type BranchLocation struct { Key string `json:"key" example:"addis_ababa" ` Name string `json:"name" example:"Addis Ababa"` } type BranchFilter struct { CompanyID ValidInt64 IsActive ValidBool BranchManagerID ValidInt64 Query ValidString CreatedBefore ValidTime CreatedAfter ValidTime } type BranchDetail struct { ID int64 Name string Location string WalletID int64 Balance Currency BranchManagerID int64 CompanyID int64 IsActive bool IsSelfOwned bool ManagerName string ManagerPhoneNumber string WalletIsActive bool ProfitPercentage float32 CompanyName string TotalBets int64 TotalStake Currency DeductedStake Currency TotalCashOut Currency TotalCashBacks Currency NumberOfUnsettled int64 TotalUnsettledAmount Currency TotalCashiers int64 StatsUpdatedAt time.Time } type SupportedOperation struct { ID int64 Name string Description string } type BranchOperation struct { ID int64 OperationName string OperationDescription string } type CreateBranch struct { Name string Location string WalletID int64 BranchManagerID int64 CompanyID int64 IsSelfOwned bool ProfitPercentage float32 } type UpdateBranch struct { ID int64 Name *string Location *string BranchManagerID *int64 CompanyID *int64 IsSelfOwned *bool IsActive *bool ProfitPercentage *float32 } type CreateSupportedOperation struct { Name string Description string } type CreateBranchOperation struct { BranchID int64 OperationID int64 } type CreateBranchReq struct { Name string `json:"name" validate:"required,min=3,max=100" example:"4-kilo Branch"` Location string `json:"location" validate:"required,min=3,max=100" example:"Addis Ababa"` BranchManagerID int64 `json:"branch_manager_id" validate:"required,gt=0" example:"1"` ProfitPercentage float32 `json:"profit_percentage" example:"0.1" validate:"lt=1" ` CompanyID *int64 `json:"company_id,omitempty" example:"1"` IsSelfOwned *bool `json:"is_self_owned,omitempty" example:"false"` Operations []int64 `json:"operations" validate:"required,dive,gt=0"` } type UpdateBranchReq struct { Name *string `json:"name,omitempty" example:"4-kilo Branch"` Location *string `json:"location,omitempty" example:"Addis Ababa"` BranchManagerID *int64 `json:"branch_manager_id,omitempty" example:"1"` CompanyID *int64 `json:"company_id,omitempty" example:"1"` IsSelfOwned *bool `json:"is_self_owned,omitempty" example:"false"` IsActive *bool `json:"is_active,omitempty" example:"false"` ProfitPercentage *float32 `json:"profit_percentage,omitempty" example:"0.1" validate:"lt=1" ` } type CreateSupportedOperationReq struct { Name string `json:"name" example:"SportsBook"` Description string `json:"description" example:"Betting on sport events"` } type SupportedOperationRes struct { ID int64 `json:"id" example:"1"` Name string `json:"name" example:"SportsBook"` Description string `json:"description" example:"Betting on sport events"` } type CreateBranchOperationReq struct { BranchID int64 `json:"branch_id" example:"1"` OperationID int64 `json:"operation_id" example:"1"` } type BranchOperationRes struct { Name string `json:"name" example:"SportsBook"` Description string `json:"description" example:"Betting on sport events"` } type BranchRes struct { ID int64 `json:"id" example:"1"` Name string `json:"name" example:"4-kilo Branch"` Location string `json:"location" example:"Addis Ababa"` WalletID int64 `json:"wallet_id" example:"1"` BranchManagerID int64 `json:"branch_manager_id" example:"1"` CompanyID int64 `json:"company_id" example:"1"` IsSelfOwned bool `json:"is_self_owned" example:"false"` IsActive bool `json:"is_active" example:"false"` ProfitPercentage float32 `json:"profit_percentage" example:"0.1"` } type BranchDetailRes struct { ID int64 `json:"id" example:"1"` Name string `json:"name" example:"4-kilo Branch"` Location string `json:"location" example:"Addis Ababa"` WalletID int64 `json:"wallet_id" example:"1"` BranchManagerID int64 `json:"branch_manager_id" example:"1"` CompanyID int64 `json:"company_id" example:"1"` IsSelfOwned bool `json:"is_self_owned" example:"false"` ManagerName string `json:"manager_name" example:"John Smith"` ManagerPhoneNumber string `json:"manager_phone_number" example:"0911111111"` Balance float32 `json:"balance" example:"100.5"` IsActive bool `json:"is_active" example:"false"` WalletIsActive bool `json:"is_wallet_active" example:"false"` ProfitPercentage float32 `json:"profit_percentage" example:"0.1"` CompanyName string `json:"company_name" example:"fortune"` TotalBets int64 `json:"total_bets"` TotalStake float32 `json:"total_stake"` DeductedStake float32 `json:"deducted_stake"` TotalCashOut float32 `json:"total_cash_out"` TotalCashBacks float32 `json:"total_cash_backs"` NumberOfUnsettled int64 `json:"number_of_unsettled"` TotalUnsettledAmount float32 `json:"total_unsettled_amount"` TotalCashiers int64 `json:"total_cashiers"` StatsUpdatedAt time.Time `json:"stats_updated_at"` } func ConvertBranch(branch Branch) BranchRes { return BranchRes{ ID: branch.ID, Name: branch.Name, Location: branch.Location, WalletID: branch.WalletID, BranchManagerID: branch.BranchManagerID, CompanyID: branch.CompanyID, IsSelfOwned: branch.IsSelfOwned, IsActive: branch.IsActive, ProfitPercentage: branch.ProfitPercentage, } } func ConvertBranchDetail(branch BranchDetail) BranchDetailRes { return BranchDetailRes{ ID: branch.ID, Name: branch.Name, Location: branch.Location, WalletID: branch.WalletID, BranchManagerID: branch.BranchManagerID, CompanyID: branch.CompanyID, IsSelfOwned: branch.IsSelfOwned, ManagerName: branch.ManagerName, ManagerPhoneNumber: branch.ManagerPhoneNumber, Balance: branch.Balance.Float32(), IsActive: branch.IsActive, WalletIsActive: branch.WalletIsActive, ProfitPercentage: branch.ProfitPercentage, CompanyName: branch.CompanyName, TotalBets: branch.TotalBets, TotalStake: branch.TotalStake.Float32(), DeductedStake: branch.DeductedStake.Float32(), TotalCashOut: branch.TotalCashOut.Float32(), TotalCashBacks: branch.TotalCashBacks.Float32(), NumberOfUnsettled: branch.NumberOfUnsettled, TotalUnsettledAmount: branch.TotalUnsettledAmount.Float32(), TotalCashiers: branch.TotalCashiers, StatsUpdatedAt: branch.StatsUpdatedAt, } } func ConvertCreateBranch(branch CreateBranch) dbgen.CreateBranchParams { return dbgen.CreateBranchParams{ Name: branch.Name, Location: branch.Location, WalletID: branch.WalletID, BranchManagerID: branch.BranchManagerID, CompanyID: branch.CompanyID, IsSelfOwned: branch.IsSelfOwned, ProfitPercent: branch.ProfitPercentage, } } func ConvertDBBranchDetail(dbBranch dbgen.BranchDetail) BranchDetail { return BranchDetail{ ID: dbBranch.ID, Name: dbBranch.Name, Location: dbBranch.Location, WalletID: dbBranch.WalletID, BranchManagerID: dbBranch.BranchManagerID, CompanyID: dbBranch.CompanyID, IsSelfOwned: dbBranch.IsSelfOwned, ManagerName: dbBranch.ManagerName.(string), ManagerPhoneNumber: dbBranch.ManagerPhoneNumber.String, Balance: Currency(dbBranch.Balance.Int64), IsActive: dbBranch.IsActive, WalletIsActive: dbBranch.WalletIsActive.Bool, ProfitPercentage: dbBranch.ProfitPercent, CompanyName: dbBranch.CompanyName, TotalBets: dbBranch.TotalBets, TotalStake: Currency(dbBranch.TotalStake), DeductedStake: Currency(dbBranch.DeductedStake), TotalCashOut: Currency(dbBranch.TotalCashOut), TotalCashBacks: Currency(dbBranch.TotalCashBacks), NumberOfUnsettled: dbBranch.NumberOfUnsettled, TotalUnsettledAmount: Currency(dbBranch.TotalUnsettledAmount), TotalCashiers: dbBranch.TotalCashiers, StatsUpdatedAt: dbBranch.StatsUpdatedAt.Time, } } func ConvertDBBranch(dbBranch dbgen.Branch) Branch { return Branch{ ID: dbBranch.ID, Name: dbBranch.Name, Location: dbBranch.Location, WalletID: dbBranch.WalletID, BranchManagerID: dbBranch.BranchManagerID, CompanyID: dbBranch.CompanyID, IsSelfOwned: dbBranch.IsSelfOwned, IsActive: dbBranch.IsActive, ProfitPercentage: dbBranch.ProfitPercent, } } func ConvertUpdateBranch(updateBranch UpdateBranch) dbgen.UpdateBranchParams { var newUpdateBranch dbgen.UpdateBranchParams newUpdateBranch.ID = updateBranch.ID if updateBranch.Name != nil { newUpdateBranch.Name = pgtype.Text{ String: *updateBranch.Name, Valid: true, } } if updateBranch.Location != nil { newUpdateBranch.Location = pgtype.Text{ String: *updateBranch.Location, Valid: true, } } if updateBranch.BranchManagerID != nil { newUpdateBranch.BranchManagerID = pgtype.Int8{ Int64: *updateBranch.BranchManagerID, Valid: true, } } if updateBranch.CompanyID != nil { newUpdateBranch.CompanyID = pgtype.Int8{ Int64: *updateBranch.CompanyID, Valid: true, } } if updateBranch.IsSelfOwned != nil { newUpdateBranch.IsSelfOwned = pgtype.Bool{ Bool: *updateBranch.IsSelfOwned, Valid: true, } } if updateBranch.IsActive != nil { newUpdateBranch.IsActive = pgtype.Bool{ Bool: *updateBranch.IsActive, Valid: true, } } if updateBranch.ProfitPercentage != nil { newUpdateBranch.ProfitPercent = pgtype.Float4{ Float32: *updateBranch.ProfitPercentage, Valid: true, } } return newUpdateBranch }