package domain

import (
	"nearle/db"
	"nearle/models"
	"nearle/utils"
	"strconv"
)

func GetModules(mid int) []models.AppModules {

	var data []models.AppModules

	q1 := `SELECT a.moduleid,a.modulename,a.logourl, 
	(SELECT COUNT(*) FROM tenants WHERE moduleid=a.moduleid) AS business, 
	(SELECT COUNT(*) FROM deliveries WHERE moduleid=a.moduleid) as orders from app_module a where a.status='Active' order by sortorder asc`

	db.DB.Raw(q1).Find(&data)

	return data
}

func GetSmsprovider(tid int) models.Smsproviders {

	var data models.Smsproviders

	q1 := `select * from smsproviders where status='Active' and templatetypeid=` + strconv.Itoa(tid)

	db.DB.Raw(q1).Find(&data)

	utils.Logger.Debugf("Query: %s", q1)

	return data
}
