package v2

import (
	"time"
)

type Brand string

const (
	Brand_Coach Brand = "coach"
)

// Article 商品
type Article struct {
	ID        uint      `gorm:"primary_key" json:"id"`
	CreatedAt time.Time `json:"createdAt"`
	UpdatedAt time.Time `json:"updatedAt"`

	Name string `gorm:"index" json:"name"`

	EnglishName string `gorm:"index" json:"englishName"`
	// 货号
	Pid string `gorm:"index:article_pid_brand,unique" json:"pid"`
	// 品牌
	Brand Brand `gorm:"index:article_pid_brand,unique" json:"brand"`
	// 描述
	Desc string `json:"desc"`
	// 图片
	Image string `json:"image"`
	// 可以购买的
	Available bool `json:"available"`
	// 排除
	Exclude bool `json:"exclude"`
	// 屏蔽 如果一个商品被屏蔽,那么所有供应商和销售商都不会继续抓取,而且页面上也不会继续显示
	Ban bool `json:"ban"`
	// 最低成本价
	CostPrice float64 `json:"costPrice"`
	// 供应商报价列表
	Providers []ProviderArticle `json:"providers" gorm:"foreignKey:ArticleID"`
	// 最低出售价
	SellPrice float64 `json:"sellPrice"`
	// 销售商报价列表
	Sellers []SellerArticle `json:"sellers" gorm:"foreignKey:ArticleID"`
	// 利润率
	Rate float64 `json:"rate" gorm:"index"` //利润率
	//备注
	Remark string `json:"remark"`
}

func (a *Article) SetBan(ban bool) *Article {
	a.Ban = ban
	for _, provider := range a.Providers {
		provider.Exclude = a.Ban
		provider.Watch = nil
	}

	for _, seller := range a.Sellers {
		seller.Exclude = a.Ban
	}
	return a
}