package prescription

import (
	ecore "simrs-vx/internal/domain/base-entities/core"
	ed "simrs-vx/internal/domain/main-entities/doctor"
	ee "simrs-vx/internal/domain/main-entities/encounter"
	epi "simrs-vx/internal/domain/main-entities/prescription-item/base"

	"time"

	erc "simrs-vx/internal/domain/references/common"
)

type Prescription struct {
	ecore.Main                          // adjust this according to the needs
	Encounter_Id *uint                  `json:"encounter_id"`
	Encounter    *ee.Encounter          `json:"encounter,omitempty" gorm:"foreignKey:Encounter_Id;references:Id"`
	Doctor_Code  *string                `json:"doctor_code" gorm:"size:20"`
	Doctor       *ed.Doctor             `json:"doctor,omitempty" gorm:"foreignKey:Doctor_Code;references:Code"`
	IssuedAt     *time.Time             `json:"issuedAt"`
	Status_Code  erc.DataStatusCode     `json:"status_code"`
	Items        []epi.PrescriptionItem `json:"items" gorm:"foreignKey:Prescription_Id;references:Id"`
}

func (d Prescription) IsNotNew() bool {
	return d.Status_Code != erc.DSCNew
}

func (d Prescription) IsApproved() bool {
	return d.Status_Code == erc.DSCDone
}
