package model

import (
	"fmt"
	"strconv"
)

func isInt(s string) error {
	_, err := strconv.Atoi(s)
	if err != nil {
		return fmt.Errorf("'%s' cannot be casted to integer", s)
	}

	return nil
}

func isPositiveOrZeroInt(s string) error {
	i, err := strconv.Atoi(s)
	if err != nil {
		return fmt.Errorf("'%s' cannot be casted to integer", s)
	}

	if i < 0 {
		return fmt.Errorf("'%s' is negative", s)
	}

	return nil
}

func isPositiveOrZeroFloat(s string) error {
	f, err := strconv.ParseFloat(s, 32)
	if err != nil {
		return fmt.Errorf("'%s' cannot be casted to floating point number", s)
	}

	if f < 0 {
		return fmt.Errorf("'%s' is negative", s)
	}

	return nil
}