package crm

import (
	"jannex/admin-dashboard-backend/modules/database"
	"jannex/admin-dashboard-backend/modules/structs"
	"jannex/admin-dashboard-backend/modules/utils"

	"git.ex.umbach.dev/Alex/roese-utils/rspagination"
)

func GetTableCustomers(params structs.CrmTypeCustomerRequest, query rspagination.PageQuery) []structs.CrmTableCustomer {
	var customers []structs.CrmTableCustomer

	if params.Type == utils.CrmPipelineCustomers {
		rspagination.DbPageQuery(database.DB,
			query,
			utils.CrmCustomersPaginationLimit,
			&customers,
			"created_at DESC",
			nil)
	} else {
		var pipeline uint8

		if params.Type == utils.CrmPipelineDmcPipeline {
			pipeline = utils.CrmPipelineDmcPipelineInt
		} else {
			pipeline = utils.CrmPipelineSetterCloserInt
		}

		rspagination.DbPageQuery(database.DB,
			query,
			utils.CrmCustomersPaginationLimit,
			&customers,
			"created_at DESC",
			structs.CrmCustomer{
				Pipeline:  pipeline,
				DealPhase: params.DealPhase})
	}

	return customers
}
