package voucher

import (
	"errors"
	"math"
)

type Rule struct {
	Type  string `json:"type"`
	Value int64  `json:"value"`
}

type Voucher struct {
	Code     string `json:"code"`
	Value    int64  `json:"discount"`
	TaxValue int64  `json:"taxValue"`
	TaxRate  int    `json:"taxRate"`
	rules    []Rule `json:"rules"`
}

type Service struct {
	// Add fields here

}

var ErrInvalidCode = errors.New("invalid vouchercode")

func (s *Service) GetVoucher(code string) (*Voucher, error) {
	value := int64(math.Round(100 * math.Pow(10, 2)))
	if code == "" {
		return nil, ErrInvalidCode
	}
	return &Voucher{
		Code:     code,
		Value:    value,
		TaxValue: int64(float64(value) * 0.2),
		TaxRate:  2500,
		rules:    nil,
	}, nil
}
