package entity

import (
	"git.gocasts.ir/ebhomengo/niki/types"
	"time"
)

type Campaign struct {
	ID           types.ID             `json:"id"`
	Title        string               `json:"title"`
	Description  string               `json:"description"`
	Link         string               `json:"link"`
	Slogan       string               `json:"slogan"` //
	GoalAmount   float64              `json:"goal_amount"`
	RaisedAmount float64              `json:"raised_amount"`
	Status       types.CampaignStatus `json:"status"`
	CreatedAt    time.Time            `json:"created_at"`
	DeadlineAt   *time.Time           `json:"deadline_at,omitempty"`
	AdminID      types.ID             `json:"creator_id"`
}

// Behavior
func (c *Campaign) Activate() {
	if c.Status == types.CampaignDraft {
		c.Status = types.CampaignActive
	}
}

func (c *Campaign) AddFunds(amount float64) {
	c.RaisedAmount += amount
	if c.RaisedAmount >= c.GoalAmount {
		c.Status = types.CampaignFinished
	}
}

func (c *Campaign) IsExpired(now time.Time) bool {
	if c.DeadlineAt == nil {
		return false
	}
	return now.After(*c.DeadlineAt)
}
