package models

import "time"

type Discount struct {
	Target      DiscountCalculationTarget `json:"target"`
	Condition   DiscountCondition         `json:"condition"`
	ID          string                    `json:"id"`
	Name        string                    `json:"name"`
	Description string                    `json:"description"`
	Layer       uint32                    `json:"layer"`
	Audit       Audit                     `json:"audit"`
	Deprecated  bool                      `json:"deprecated"`
}

type Audit struct {
	UpdatedAt time.Time  `json:"updatedAt"`
	DeletedAt *time.Time `json:"deletedAt,omitempty"`
	CreatedAt time.Time  `json:"createdAt"`
	Deleted   bool       `json:"deleted"`
}

type DiscountCalculationTarget struct {
	Products    []ProductTarget `json:"products"`
	Factor      float64         `json:"factor"`
	TargetScope TargetScope     `json:"scope"`
	TargetGroup string          `json:"group"`
	Overhelm    bool            `json:"overhelm"`
}

type DiscountCondition struct {
	Period              *PeriodCondition `json:"period,omitempty"`
	Product             *string          `json:"product,omitempty"`
	PriceFrom           *float64         `json:"priceFrom,omitempty"`
	Group               *string          `json:"group,omitempty"`
	User                *string          `json:"user,omitempty"`
	UserType            *string          `json:"userType,omitempty"`
	Coupon              *string          `json:"coupon,omitempty"`
	PurchasesAmount     *float64         `json:"purchasesAmount,omitempty"`
	CartPurchasesAmount *float64         `json:"cartPurchasesAmount,omitempty"`

	/* Срок использования (количество дней использования) */
	Term *uint64 `json:"term"`

	/* Количество использований (количество попыток) */
	Usage *uint64 `json:"usage"`
}

type ProductTarget struct {
	ID       string  `json:"productId"`
	Factor   float64 `json:"factor"`
	Overhelm bool    `json:"overhelm"`
}

type PeriodCondition struct {
	From time.Time `json:"from"`
	To   time.Time `json:"to"`
}

type TargetScope string

const (
	TargetSum   TargetScope = "sum"
	TargetGroup TargetScope = "group"
	TargetEach  TargetScope = "each"
)
