package model

import (
	"time"

	"gorm.io/gorm"
	"src.whiteboxsystems.nl/DECOZO/okapi"
	"src.whiteboxsystems.nl/DECOZO/okapidemo/sharedmodel"
)

type ConnectionState string

const (
	ConnectionStatePending   = ConnectionState("pending")
	ConnectionStateCompleted = ConnectionState("completed")
)

type ServiceProvider struct {
	gorm.Model
	Reference    string
	AuthConfigID uint
	AuthConfig   *sharedmodel.XISAuthConfig
	State        ConnectionState
	Addr         string
	Supplier     string
	System       string
	Services     []Service
}

type Service struct {
	gorm.Model
	ServiceProviderID  uint
	ServiceProvider    *ServiceProvider `json:"ServiceProvider,omitempty"`
	ServiceID          string
	Name               string
	Description        string
	SubscriptionPolicy okapi.SubscriptionPolicy
	ConsentPolicy      okapi.ConsentPolicy
	AuthConfigID       uint
	AuthConfig         *sharedmodel.AuthConfig
	Subscriptions      []Patient `gorm:"many2many:service_patients;"`
}

type Consent struct {
	gorm.Model
	ServiceProviderID uint
	ServiceID         string
	PatientID         uint    `json:"-"`
	Patient           Patient `json:"-"`
	ConsentGivenOn    *time.Time
	VerbalConsent     bool
	Brochure          string
	Brochureversion   string
}

type Patient struct {
	gorm.Model
	ExternalId       string
	ExternalIdSystem string
	Name             string
	Birthdate        string
	PatientID        string
	FileBase         string
	Consent          []Consent
}
