package services

import (
	"nearle/models"
	"nearle/repositories"
)

type OrderService interface {
	GetTenantOrders(input models.DeliveryQuery) ([]models.OrderInfo, error)
	GetPartnerOrders(stat, fdate, tdate string, pid, pageno, pagesize int, keyword string) ([]models.OrderInfo, error)
	GetCustomerOrders(stat, fdate, tdate string, cid, mid, pageno, pagesize int, keyword string) ([]models.OrderInfo, error)
	GetAdminOrders(stat, fdate, tdate string, aid, pageno, pagesize int, keyword string) ([]models.OrderInfo, error)
	GetUserOrders(stat, fdate, tdate string, uid, pageno, pagesize int, keyword string) ([]models.OrderInfo, error)
	GetAllOrders(stat, fdate, tdate string, pageno, pagesize int, keyword string) ([]models.OrderInfo, error)
	GetOrderSummary(tid, pid, cid, lid int, fdate, tdate string) ([]models.Ordersummarydaily, error)
	GetLocationOrderSummary(tenantID int) ([]models.Ordersummarylocation, error)
	GetOrderInsights(tenantID int) ([]models.OrderInsightv1, error)
	GetOrderDetails(orderHeaderID int) ([]models.OrderDetails, error)
	UpdateOrder(order *models.Orders) error
	CreateOrder(order models.Orders) (models.Orders, error)
	UploadOfflineSales(input models.OfflineSalesUpload) (*models.OfflineSalesUploadResponse, error)
	GetCustomerOrdersv3(customerID, tenantID, moduleID, fromDate, toDate, orderStatus, keyword string, pageSize, offset int) ([]models.CustomerOrder, error)
	GetTenantLocationOrders(input models.DeliveryQuery) ([]models.OrderInfo, error)
	GetRevenueSummary(tid, lid int, fdate, tdate string) (*models.TenantRevenueSummary, error)
	GetSalesSummary(tid, lid int, fdate, tdate string) (*models.SalesSummaryResponse, error)
	GetTimeSeries(tenantID, locationID int, granularity, fromDate, toDate string) ([]models.TimeSeriesData, error)
}

type orderService struct {
	repo repositories.OrderRepository
}

func NewOrderService(repo repositories.OrderRepository) OrderService {
	return &orderService{repo: repo}
}

func (s *orderService) GetTenantOrders(input models.DeliveryQuery) ([]models.OrderInfo, error) {
	return s.repo.GetTenantOrders(input)
}

func (s *orderService) GetPartnerOrders(stat, fdate, tdate string, pid, pageno, pagesize int, keyword string) ([]models.OrderInfo, error) {
	return s.repo.GetPartnerOrders(stat, fdate, tdate, pid, pageno, pagesize, keyword)
}

func (s *orderService) GetCustomerOrders(stat, fdate, tdate string, cid, mid, pageno, pagesize int, keyword string) ([]models.OrderInfo, error) {
	return s.repo.GetCustomerOrders(stat, fdate, tdate, cid, mid, pageno, pagesize, keyword)
}

func (s *orderService) GetAdminOrders(stat, fdate, tdate string, aid, pageno, pagesize int, keyword string) ([]models.OrderInfo, error) {
	return s.repo.GetAdminOrders(stat, fdate, tdate, aid, pageno, pagesize, keyword)
}

func (s *orderService) GetUserOrders(stat, fdate, tdate string, uid, pageno, pagesize int, keyword string) ([]models.OrderInfo, error) {
	return s.repo.GetUserOrders(stat, fdate, tdate, uid, pageno, pagesize, keyword)
}

func (s *orderService) GetAllOrders(stat, fdate, tdate string, pageno, pagesize int, keyword string) ([]models.OrderInfo, error) {
	return s.repo.GetAllOrders(stat, fdate, tdate, pageno, pagesize, keyword)
}

func (s *orderService) GetOrderSummary(tid, pid, cid, lid int, fdate, tdate string) ([]models.Ordersummarydaily, error) {
	return s.repo.GetOrderSummary(tid, pid, cid, lid, fdate, tdate)
}

func (s *orderService) GetLocationOrderSummary(tenantID int) ([]models.Ordersummarylocation, error) {
	return s.repo.GetLocationOrderSummary(tenantID)
}

func (s *orderService) GetOrderInsights(tenantID int) ([]models.OrderInsightv1, error) {
	return s.repo.GetOrderInsights(tenantID)
}

func (s *orderService) GetOrderDetails(orderHeaderID int) ([]models.OrderDetails, error) {
	return s.repo.GetOrderDetails(orderHeaderID)
}

func (s *orderService) UpdateOrder(order *models.Orders) error {
	return s.repo.UpdateOrder(order)
}

func (s *orderService) CreateOrder(order models.Orders) (models.Orders, error) {
	return s.repo.CreateOrder(order)
}

func (s *orderService) UploadOfflineSales(input models.OfflineSalesUpload) (*models.OfflineSalesUploadResponse, error) {
	return s.repo.UploadOfflineSales(input)
}

func (s *orderService) GetCustomerOrdersv3(customerID, tenantID, moduleID, fromDate, toDate, orderStatus, keyword string, pageSize, offset int) ([]models.CustomerOrder, error) {
	return s.repo.GetCustomerOrdersv3(customerID, tenantID, moduleID, fromDate, toDate, orderStatus, keyword, pageSize, offset)
}

func (s *orderService) GetTenantLocationOrders(input models.DeliveryQuery) ([]models.OrderInfo, error) {
    return s.repo.GetTenantLocationOrders(input)
}

func (s *orderService) GetRevenueSummary(tid, lid int, fdate, tdate string) (*models.TenantRevenueSummary, error) {
	return s.repo.GetRevenueSummary(tid, lid, fdate, tdate)
}

func (s *orderService) GetSalesSummary(tid, lid int, fdate, tdate string) (*models.SalesSummaryResponse, error) {
	return s.repo.GetSalesSummary(tid, lid, fdate, tdate)
}

func (s *orderService) GetTimeSeries(tenantID, locationID int, granularity, fromDate, toDate string) ([]models.TimeSeriesData, error) {
	return s.repo.GetTimeSeries(tenantID, locationID, granularity, fromDate, toDate)
}

