package models

import (
	"fmt"
	"gorm.io/gorm"
)

/*
Sticker
  - name, abstr, descr, price, tag

Poster
  - name, abstr, descr, price bw/colored, tag

Zines
  - name, abstr, descr, price bw/colored/coloredcoveronly, tag

Books
  - name, abstr, descr, price, tag
*/
type Category string

const (
	Zine Category = "Zine"
)

func ParseCategory(s string) (c Category, err error) {
	if s == "Zine" {
		return Zine, nil
	}

	return c, fmt.Errorf("Cannot parse category %s", s)
}

type ItemVariant struct {
	gorm.Model
	Name       string  `json:"name" gorm:"not null"`
	Price      float64 `json:"price" gorm:"not null"`
	InStock    bool    `json:"inStock" gorm:"default:true"`
	ShopItemID uint
}

type ShopItem struct {
	gorm.Model
	Name               string        `json:"name" binding:"required" gorm:"unique;not null"`
	Abstract           string        `json:"abstract" binding:"required"`
	Description        string        `json:"description" binding:"required"`
	Category           Category      `json:"category"`
	Variants           []ItemVariant `json:"variant"`
	BasePrice          float64       `json:"basePrice"`
	IsPublic           bool          `json:"isPublic" gorm:"default:true"`
	Tags               []Tag         `gorm:"many2many:item_tags;"`
	Image              string
	Pdf                string
	PrintMode          string `json:"printMode" gorm:"default:CreateBooklet"`
	CustomPrintOptions string `gorm:"default:''"`
	FitToPage          bool   `gorm:"default:false"`
	WasPrinted         bool   `gorm:"default:false"`
}
