package kfa

import (
	"encoding/json"
	"time"
)

type KfaProduct struct {
	ID                  int64           `gorm:"primaryKey;autoIncrement"`
	KfaCode             string          `gorm:"type:varchar(20);uniqueIndex;not null"`
	Name                string          `gorm:"type:varchar(150);not null"`
	DisplayName         *string         `gorm:"type:text"`
	TradeName           *string         `gorm:"type:varchar(150)"`
	State               *string         `gorm:"type:varchar(20)"`
	IsGeneric           *bool           `gorm:"default:false"`
	DosageForm          json.RawMessage `gorm:"type:jsonb"`
	FarmalkesType       json.RawMessage `gorm:"type:jsonb"`
	Route               json.RawMessage `gorm:"type:jsonb"`
	ControlledDrug      json.RawMessage `gorm:"type:jsonb"`
	Uom                 json.RawMessage `gorm:"type:jsonb"`
	FixPrice            *float64        `gorm:"type:numeric(12,2)"`
	HetPrice            *float64        `gorm:"type:numeric(12,2)"`
	DosePerUnit         *float64        `gorm:"type:numeric(10,2)"`
	NetWeight           *float64        `gorm:"type:numeric(10,2)"`
	NetWeightUom        *string         `gorm:"type:varchar(20)"`
	Volume              *float64        `gorm:"type:numeric(10,2)"`
	VolumeUom           *string         `gorm:"type:varchar(20)"`
	ScoreTkdn           *float64        `gorm:"type:numeric(5,2)"`
	ScoreTkdnBmp        *float64        `gorm:"type:numeric(5,2)"`
	ScoreBmp            *float64        `gorm:"type:numeric(5,2)"`
	Rxterm              *int            `gorm:"type:int4"`
	Manufacturer        *string         `gorm:"type:varchar(150)"`
	Registrar           *string         `gorm:"type:varchar(150)"`
	Nie                 *string         `gorm:"type:varchar(100)"`
	Hscode              *string         `gorm:"type:varchar(100)"`
	LkppCode            *string         `gorm:"type:varchar(100)"`
	IsLkppActive        *bool           `gorm:"default:true"`
	Description         *string         `gorm:"type:text"`
	Indication          *string         `gorm:"type:text"`
	SideEffect          *string         `gorm:"type:text"`
	Warning             *string         `gorm:"type:text"`
	Image               *string         `gorm:"type:varchar(100)"`
	DrugClassification  *string         `gorm:"type:varchar(100)"`
	ManufacturingOrigin *string         `gorm:"type:varchar(100)"`
	AtcInfo             json.RawMessage `gorm:"type:jsonb"`
	Fornas              json.RawMessage `gorm:"type:jsonb"`
	DosageUsage         json.RawMessage `gorm:"type:jsonb"`
	Tags                json.RawMessage `gorm:"type:jsonb"`
	IdentifierIds       json.RawMessage `gorm:"type:jsonb"`
	ProductTemplate     json.RawMessage `gorm:"type:jsonb"`
	Replacement         json.RawMessage `gorm:"type:jsonb"`
	Ucum                json.RawMessage `gorm:"type:jsonb"`
	CreatedAt           time.Time       `gorm:"autoCreateTime"`
	UpdatedAt           time.Time       `gorm:"autoUpdateTime"`
	Active              *bool           `gorm:"default:true"`
}

func (KfaProduct) TableName() string {
	return "master.kfa_products"
}

type KfaProductActiveIngredient struct {
	ID             int64     `gorm:"primaryKey;autoIncrement"`
	ProductKfaCode string    `gorm:"type:varchar(20);index"`
	ProductDisplay string    `gorm:"type:text"`
	SubstanceCode  string    `gorm:"type:varchar(20)"`
	SubstanceName  string    `gorm:"type:varchar(150)"`
	StrengthValue  *float64  `gorm:"type:numeric(10,2)"`
	StrengthUnit   string    `gorm:"type:varchar(20)"`
	StrengthText   string    `gorm:"type:varchar(100)"`
	State          string    `gorm:"type:varchar(20)"`
	CreatedAt      time.Time `gorm:"autoCreateTime"`
	UpdatedAt      time.Time `gorm:"autoUpdateTime"`
	Active         *bool     `gorm:"default:true"`
}

func (KfaProductActiveIngredient) TableName() string {
	return "master.kfa_product_active_ingredients"
}

type KfaProductPackaging struct {
	ID             int64     `gorm:"primaryKey;autoIncrement"`
	ProductKfaCode string    `gorm:"type:varchar(20);index"`
	ProductDisplay string    `gorm:"type:text"`
	Code           string    `gorm:"type:varchar(20)"`
	Name           string    `gorm:"type:varchar(150)"`
	Quantity       int       `gorm:"type:int4"`
	Unit           string    `gorm:"type:varchar(50)"`
	Price          *float64  `gorm:"type:numeric(12,2)"`
	State          string    `gorm:"type:varchar(20)"`
	CreatedAt      time.Time `gorm:"autoCreateTime"`
	UpdatedAt      time.Time `gorm:"autoUpdateTime"`
	Active         *bool     `gorm:"default:true"`
}

func (KfaProductPackaging) TableName() string {
	return "master.kfa_product_packagings"
}
