package analytic

import (
	"fmt"
	"github.com/jalaali/go-jalaali"
	"time"
)

func normalizeLimitOffset(limit, offset int) (int, int) {
	if limit <= 0 {
		limit = 50
	}
	if limit > 100 {
		limit = 100
	}
	if offset < 0 {
		offset = 0
	}
	return limit, offset
}

// convert age range -> DOB range
func ageRangeToDOB(minAge, maxAge *int, now time.Time) (dobFrom, dobTo *string) {
	if maxAge != nil {
		t := now.AddDate(-(*maxAge + 1), 0, 1)
		jy, jm, jd, err := jalaali.ToJalaali(t.Year(), t.Month(), t.Day())
		if err != nil {
		}
		s := fmt.Sprintf("%04d/%02d/%02d", jy, jm, jd)
		dobFrom = &s
	}

	if minAge != nil {
		t := now.AddDate(-*minAge, 0, 0)
		jy, jm, jd, err := jalaali.ToJalaali(t.Year(), t.Month(), t.Day())
		if err != nil {
		}
		s := fmt.Sprintf("%04d/%02d/%02d", jy, jm, jd)
		dobTo = &s
	}

	return
}
